when drawImage a empty C2S context

Null pointer error will be thrown when ctx.drawImage(ctx) with an empty C2S context with no childNodes.

These code may fix the problem.
This commit is contained in:
Fu Zhen 2015-11-26 22:31:35 +08:00
parent ec6e29af6c
commit 8a8d081561

View File

@ -1038,6 +1038,7 @@
//canvas2svg mock canvas context. In the future we may want to clone nodes instead.
//also I'm currently ignoring dw, dh, sw, sh, sx, sy for a mock context.
svg = image.getSvg();
if (svg.childNodes && svg.childNodes.length > 1) {
defs = svg.childNodes[0];
while(defs.childNodes.length) {
id = defs.childNodes[0].getAttribute("id");
@ -1045,10 +1046,13 @@
this.__defs.appendChild(defs.childNodes[0]);
}
group = svg.childNodes[1];
if (group) {
parent.appendChild(group);
this.__currentElement = group;
this.translate(dx, dy);
this.__currentElement = currentElement;
}
}
} else if(image.nodeName === "CANVAS" || image.nodeName === "IMG") {
//canvas or image
svgImage = this.__createElement("image");