BUG: HTML5 target crashes when drawing Shape to BitmapData


#1

I needed a default bitmap to use in place of missing assets, so I filled a Shape instance with a gradient and drew it to a BitmapData instance. It works fine in the Flash export, but in HTML5 it crashes.

I can avoid crashing if I comment out “bmpd.draw(…)”.

var m:Matrix = new Matrix();
m.createGradientBox(500, 350);
var shape:Shape = new Shape();
shape.graphics.beginGradientFill( GradientType.LINEAR, [0xff0000, 0x000099], [1, 1], [0, 255], m );
shape.graphics.drawRect(0, 0, 1000, 350);
shape.graphics.endFill();
var bmpd:BitmapData = new BitmapData( 1000, 350, false, 0xffffff );
bmpd.draw(shape);
return bmpd;

Console output (debug mode):
Uncaught TypeError: Cannot read property ‘clear’ of undefined
at Function.openfl__$internal_renderer_canvas_CanvasGraphics.render (CanvasGraphics.hx:1322)
at openfl_display_Shape.__renderCanvas (DisplayObject.hx:819)
at openfl_display_CanvasRenderer.__render (CanvasRenderer.hx:192)
at openfl_display_BitmapData.__drawCanvas (BitmapData.hx:1669)
at openfl_display_BitmapData.draw (BitmapData.hx:649)

Console output (release mode):
Uncaught TypeError: Cannot read property ‘clear’ of undefined
at Function.openfl__$internal_renderer_canvas_CanvasGraphics.render (PokerQuest.js:57998)
at openfl_display_Shape.__renderCanvas (PokerQuest.js:1321)
at openfl_display_CanvasRenderer.__render (PokerQuest.js:71526)
at openfl_display_BitmapData.__drawCanvas (PokerQuest.js:9265)
at openfl_display_BitmapData.draw (PokerQuest.js:8725)


#2

Does it work if you replace Shape with Sprite?


#3

It does not. Almost the exact same error message, but now it’s “Sprite.__renderCanvas” instead of “Shape.__renderCanvas”


#4

This appears to work properly in the latest development build of OpenFL, so I think this will be good once we have the next OpenFL release


#5

Strange, i have almost the same code here and it works fine with Sprite


#6

@Karg are you using the dev build? I’m using the official OpenFL 8.3.0 release. As @singmajesty says, it seems to be working in the dev builds.


#7

That was tested in 8.2.0