Webgraphics drives me nuts! Bug?

I’m using the simple webgraphics boxes example with Xojo 2019R3 on my Mac which works fine.

I modifiy the code and it works fine:

[code]Sub Paint(g as WebGraphics) Handles Paint

g.ClearRect(0, 0, g.Width, g.Height)

g.ForeColor = &cff0000
g.TextFont = “Helvetica”
g.TextSize = 16

g.DrawString(“Hello world!”, 10, 130)

End Sub[/code]

I add a TextArea with some text and change the code to

[code]Sub Paint(g as WebGraphics) Handles Paint

g.ClearRect(0, 0, g.Width, g.Height)

g.ForeColor = &cff0000
g.TextFont = “Helvetica”
g.TextSize = 16
g.DrawString(TextArea1.Text, 50, 130)

g.DrawString(“Hello world!”, 10, 130)

End Sub[/code]

and nothing is shown on the webcanvas, not even the “Hello World!”.

I comment out the g.DrawString(TextArea1.Text, 50, 130) line and it paints the “Hello World!” just fine.

I can have two .DrawString lines just fine:

g.DrawString("Hello world!", 10, 130) g.DrawString("Jurassic world!", 10, 160)

Where am I going wrong?

What text is in the text area? I know it shouldn’t matter, but let’s narrow this down first.

I would suggest

Dim s As String = TextArea1.text g.DrawString(s, 50, 150)

and see how that works. What is the encoding for s?

BTW where can I find 2019R3? Is Android available?

Just some random text that I typed in.

[quote=434689:@Wayne Golding]I would suggest

Dim s As String = TextArea1.text g.DrawString(s, 50, 150)

and see how that works. What is the encoding for s?[/quote]

Had already tried that. All internal Xojo strings are UTF8. There are no non-ASCII characters in my text, just some random letters like “kgrdfcvh”

[quote=434685:@Richard Duke][/quote]
Would be nice, but alas, I’m not a time traveller (but then I would say that, wouldn’t I?) …

ok, so in the browser you’re running on, open the developer console and run your app again. My suspicion is that there’s a javascript error of some kind happening when you draw the string, and I was hoping it was going to be something as simple as an encoding issue or a wayward apostrophe or quote that was causing the issue.

Anyway, if it is a Javascript error in the graphics code translation and we can track it down we can probably figure out what’s going on.

Oh, and have you tried turning off the Diff Engine for that canvas?

Ok, found the problem. If the TextArea has an EndOfLine in it (I usually press the return at the end of a line) then it will prevent all drawing.

So the following code works fine

g.DrawString("Hello world!", 10, 130) g.DrawString("Jurassic world!", 10, 160)

but this one results in an empty canvas:

g.DrawString("Hello world!", 10, 130) g.DrawString("Jurassic world!" + EndOfLine, 10, 160)

The same if I add an EndOfLine.Unix.

If I add an EndOfLine.Macintosh or EndOfLine.Windows I get a crash:

Could not execute returned javascript: Unexpected EOF
Source: try {
Xojo.controls[‘m7eEZ2sZ’].editScript(1,‘context.clearRect(0,0,1147,748);’,23);
Xojo.controls[‘m7eEZ2sZ’].editScript(1,‘context.clearRect(0,0,1147,748);’,24);
Xojo.controls[‘m7eEZ2sZ’].editScript(1,‘context.font = \‘16px Helvetica\’;’,25);
Xojo.controls[‘m7eEZ2sZ’].editScript(1,‘context.fillStyle = \‘rgba(255,0,0,1.0)\’;’,26);
Xojo.controls[‘m7eEZ2sZ’].editScript(1,‘context.fillText(\‘Hello world!\’,10,130);’,27);
Xojo.controls[‘m7eEZ2sZ’].editScript(1,‘context.font = \‘16px Helvetica\’;’,28);
Xojo.controls[‘m7eEZ2sZ’].editScript(1,‘context.fillStyle = \‘rgba(255,0,0,1.0)\’;’,29);
Xojo.controls[‘m7eEZ2sZ’].editScript(1,‘context.fillText(\‘Jurassic world!
\’,10,160);’,30);
Xojo.controls[‘m7eEZ2sZ’].runScript(2);
} catch(ex) { }

Bug I presume?

<https://xojo.com/issue/55604>

Thanks Markus. Its amazing my to me that no one has run into this before now.

Dito. I thought it must be something I’m doing wrong because surely that would have been reported before …

And thanks for your help!