add protected code when rect.width or rect.height is 0

This commit is contained in:
Huabing.Xu
2016-02-17 10:29:40 +08:00
parent dd610d4c30
commit 8e4a381e04
+8 -3
View File
@@ -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();