diff --git a/src/virtual-machine.js b/src/virtual-machine.js index b610d193e..2de3646c6 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -850,10 +850,13 @@ class VirtualMachine extends EventEmitter { costume.rotationCenterX = rotationCenterX; costume.rotationCenterY = rotationCenterY; + // If the bitmap originally had a zero width or height, use that value + const bitmapWidth = bitmap.sourceWidth === 0 ? 0 : bitmap.width; + const bitmapHeight = bitmap.sourceHeight === 0 ? 0 : bitmap.height; // @todo: updateBitmapSkin does not take ImageData const canvas = document.createElement('canvas'); - canvas.width = bitmap.width; - canvas.height = bitmap.height; + canvas.width = bitmapWidth; + canvas.height = bitmapHeight; const context = canvas.getContext('2d'); context.putImageData(bitmap, 0, 0); @@ -873,7 +876,7 @@ class VirtualMachine extends EventEmitter { const storage = this.runtime.storage; costume.dataFormat = storage.DataFormat.PNG; costume.bitmapResolution = bitmapResolution; - costume.size = [bitmap.width, bitmap.height]; + costume.size = [bitmapWidth, bitmapHeight]; costume.asset = storage.createAsset( storage.AssetType.ImageBitmap, costume.dataFormat, @@ -885,7 +888,10 @@ class VirtualMachine extends EventEmitter { costume.md5 = `${costume.assetId}.${costume.dataFormat}`; this.emitTargetsUpdate(); }); - reader.readAsArrayBuffer(blob); + // Bitmaps with a zero width or height return null for their blob + if (blob){ + reader.readAsArrayBuffer(blob); + } }); }