Issue on firefox 27.0.1 of CCSprite

Issue on firefox 27.0.1 of CCSprite
0.0 0


My game works very well on Chrome and Safari, but on Firefox 27.0.1, it gave me this error:

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

The error was caused by the function _drawForCanvas of the CCSprite.

if (this._texture && locTextureCoord.validRect) {
            var image = this._texture.getHtmlElementObj();
            if (this._colorized) {
                    0, 0, locTextureCoord.width, locTextureCoord.height,
                    flipXOffset, flipYOffset, locDrawSizeCanvas.width, locDrawSizeCanvas.height);
            } else {
                    locTextureCoord.x, locTextureCoord.y, locTextureCoord.width,  locTextureCoord.height,
                  ------error------flipXOffset, flipYOffset, locDrawSizeCanvas.width , locDrawSizeCanvas.height);
        } else if (locContentSize._width !== 0) {
            var curColor = this.getColor();
            context.fillStyle = "rgba(" + curColor.r + "," + curColor.g + "," + curColor.b + ",1)";
            context.fillRect(flipXOffset, flipYOffset, locContentSize._width * locEGL_ScaleX, locContentSize._height * locEGL_ScaleY);

Someone could give me some hint? Thanks!


Could you please tell me what the version of Cocos2d-html5 you’re using is?



Just for information regarding this. I just spent the last few days working out the same issue. The problem is caused by firefox not allowing you to set a texture rect on an image if the image is smaller than the rect. Basically, if you set a rect of (0,0,320,320) on an image with size (280,520), this bug will be triggered because the width of the rect is bigger than the width of the image. This does not trigger in chrome.

The easiest way to solve this in your code is to test the content size of your texture node and use that if it’s smaller than your default rect size… so (0,0,280,320) in this case.


@spork, thanks!