diff --git a/cocos2d/core/textures/CCTexture2D.js b/cocos2d/core/textures/CCTexture2D.js index c3ea9107b1..3263bfbb16 100644 --- a/cocos2d/core/textures/CCTexture2D.js +++ b/cocos2d/core/textures/CCTexture2D.js @@ -701,6 +701,8 @@ game.once(game.EVENT_RENDERER_INITED, function () { var textureImage = this._htmlElementObj; if(!rect) rect = cc.rect(0, 0, textureImage.width, textureImage.height); + if(!rect.width || !rect.height) + return; canvas.width = rect.width; canvas.height = rect.height; @@ -737,6 +739,9 @@ game.once(game.EVENT_RENDERER_INITED, function () { if(!rect) rect = cc.rect(0, 0, textureImage.width, textureImage.height); + if(!rect.width || !rect.height) + return; + canvas.width = rect.width; canvas.height = rect.height; @@ -748,9 +753,6 @@ game.once(game.EVENT_RENDERER_INITED, function () { 0, 0, rect.width, rect.height ); - if(onlyCanvas) - return canvas; - var imageData = context.getImageData(0,0,canvas.width, canvas.height); var data = imageData.data; r = r/255; @@ -764,6 +766,9 @@ game.once(game.EVENT_RENDERER_INITED, function () { context.putImageData(imageData, 0, 0); + if(onlyCanvas) + return canvas; + var newTexture = new Texture2D(); newTexture.initWithElement(canvas); newTexture.handleLoadedTexture();