grinmonk Posted April 25, 2018 Share Posted April 25, 2018 We moved our game from Phaser 2.6.2 "Kore Springs" to 2.10.3 and encountered this error in Firefox and Internet Explorer: IndexSizeError: Index or size is negative or greater than the allowed amount The exception is trown from PIXI.Sprite.prototype._renderCanvas: renderSession.context.drawImage(this.texture.baseTexture.source, cx, cy, cw, ch, dx, dy, cw / resolution, ch / resolution); The arguments are: cx : 803 cy : 899.37 cw : 168 ch : 0 dx : -0 dy : -0.6299999999999955 resolution : 1 Everything was fine in "Kore Springs" but we wanted to take advantage of all the fixes and updates on tilemaps in CE. Link to comment Share on other sites More sharing options...
samme Posted April 25, 2018 Share Posted April 25, 2018 I think the ch=0 is the problem. Can you tell where that value is coming from? grinmonk 1 Link to comment Share on other sites More sharing options...
grinmonk Posted April 26, 2018 Author Share Posted April 26, 2018 15 hours ago, samme said: I think the ch=0 is the problem. Can you tell where that value is coming from? Initially the height value comes from here: But then it gets rounded to zero: Link to comment Share on other sites More sharing options...
samme Posted April 27, 2018 Share Posted April 27, 2018 Thanks. Is it a sprite with a crop rectangle? You may be able to avoid the error by doing obj.texture.crop.width |= 0; obj.texture.crop.height |= 0; after you set or modify the crop. Link to comment Share on other sites More sharing options...
grinmonk Posted April 28, 2018 Author Share Posted April 28, 2018 @samme Thanks for your response! Am I correct that you suggest to replace Math.floor with bitwise OR? But aren't the results going to be the same? Could you please explain in more detail or point out where can I read about it? Thanks! Link to comment Share on other sites More sharing options...
samme Posted April 28, 2018 Share Posted April 28, 2018 I meant that if you floor the crop dimensions yourself, during updates, you may be able to avoid the error in during rendering. It doesn't really matter if you use Math.floor or the bitwise operation. You could do: function update() { // ... obj.crop(/* ... */); var crop = object.texture.crop; // Avoid error in Sprite._renderCanvas: crop.width = Math.floor(crop.width); crop.height = Math.floor(crop.height); // ... } It expect it will work because Sprite._renderCanvas skips objects with crop dimensions of exactly 0. I haven't tested it though. Probably we should add a fix in Phaser CE for this. Link to comment Share on other sites More sharing options...
samme Posted April 30, 2018 Share Posted April 30, 2018 phaser-ce/issues/532 grinmonk 1 Link to comment Share on other sites More sharing options...
grinmonk Posted May 4, 2018 Author Share Posted May 4, 2018 @samme Thanks a lot! I will try your suggestion out. And thanks for the fix. Link to comment Share on other sites More sharing options...
Recommended Posts