Skip to content

Commit ed889bc

Browse files
authored
Merge pull request #539 from adroitwhiz/zero-size
Set zero-sized SVG MIPs to empty texture
2 parents 570fa98 + 6d9cec8 commit ed889bc

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/SVGSkin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ class SVGSkin extends Skin {
8080
// updating Silhouette and is better handled by more browsers in
8181
// regards to memory.
8282
const canvas = this._svgRenderer.canvas;
83+
// If one of the canvas dimensions is 0, set this MIP to an empty image texture.
84+
// This avoids an IndexSizeError from attempting to getImageData when one of the dimensions is 0.
85+
if (canvas.width === 0 || canvas.height === 0) return super.getTexture();
86+
8387
const context = canvas.getContext('2d');
8488
const textureData = context.getImageData(0, 0, canvas.width, canvas.height);
8589

@@ -105,10 +109,6 @@ class SVGSkin extends Skin {
105109
* @return {WebGLTexture} The GL texture representation of this skin when drawing at the given scale.
106110
*/
107111
getTexture (scale) {
108-
if (!this._svgRenderer.canvas.width || !this._svgRenderer.canvas.height) {
109-
return super.getTexture();
110-
}
111-
112112
// The texture only ever gets uniform scale. Take the larger of the two axes.
113113
const scaleMax = scale ? Math.max(Math.abs(scale[0]), Math.abs(scale[1])) : 100;
114114
const requestedScale = Math.min(scaleMax / 100, this._maxTextureScale);

0 commit comments

Comments
 (0)