openfl / openfl-html5

[deprecated] OpenFL HTML5 backend
Other
0 stars 1 forks source link

IndexSizeError: Index or size is negative or greater than the allowed amount #8

Closed jgranick closed 10 years ago

jgranick commented 10 years ago

8 Issue by alagatar,

In haxelib version openfl-html5 1,1,0-beta present bug: "IndexSizeError: Index or size is negative or greater than the allowed amount" I found way to fix that: flash/display/Graphics.hx Add code to line 645 if(rect.width < 1) { rect.width=1; } if(rect.height < 1) { rect.height=1; }

jgranick commented 10 years ago

Comment by jgranick:

That's strange,

How are you ending up with tile rectangles that are less than one pixel in size? Are these displayed when testing other targets?

Perhaps in openfl.display.Tilesheet, it should check if it is smaller than 1 in width or height, and save a null rectangle instead, so it is skipped while rendering?

jgranick commented 10 years ago

Comment by alagatar:

Maybe error becouse rectangle is null. I don't know how error present. I use tilelayer and sometimes receive this error. All graphics renderend by tilelayer removes form stage when error appear. Error only on html5 target.

jgranick commented 10 years ago

Comment by jgranick:

Would you mind testing something for me?

Remove your changes to flash.display.Graphics then make the following addition at the start of addTileRect in openfl.display.Tilesheet

if (rectangle == null || rectangle.width < 1 || rectangle.height < 1) {

    __tileRects.push (null);
    __centerPoints.push (null);
    __tileUVs.push (null);

}

I think this would resolve the error, and possibly perform better

jgranick commented 10 years ago

Comment by alagatar:

I remove my fix and add your code. Without any changes error appear continuasly every frame. With your code only 6 times. Its appear on execution code: flash.display.Graphics: ctx.drawImage(surface,rect.x,rect.y,rect.width,rect.height,-center.x * scale,-center.y * scale,rect.width * scale,rect.height * scale);

jgranick commented 10 years ago

Comment by jgranick:

Does it work if you modify line 616 in flash.display.Graphics, like this?

if (rect != null && rect.width > 0 && rect.height > 0 && center != null) {

Even better, do you have any way of finding exactly what data is being passed in? That would make it much easier to test against, and try to find the best solution. Ideally, I want to keep the number of checks in the render loop as minimal as possible, but of course we don't errors.

Thank you!

jgranick commented 10 years ago

Comment by alagatar:

Great, your code fix this issue. This issue appered when use tilelayer and use animated TileClip

jgranick commented 10 years ago

Comment by jgranick:

Committed, thanks again for your help!