From 530afb1a60461bdc6f9ab896a0137c25de256382 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Tue, 9 Apr 2019 10:27:55 +0200 Subject: [PATCH] let "getImageAttribute" deal with null costumes --- HISTORY.md | 1 + src/objects.js | 21 +++++++++++++-------- src/threads.js | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index d57bdc56..f0fd6a53 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -64,6 +64,7 @@ ### 2019-04-09 * Blocks, Objects, Threads: new "getImageAttribute" reporter primitive +* Objects, Threads: let "getImageAttribute" deal with null costumes ### 2019-04-08 * Blocks, Objects, Threads: new "getSoundAttribute" reporter primitive diff --git a/src/objects.js b/src/objects.js index 3c535eeb..43bab5d0 100644 --- a/src/objects.js +++ b/src/objects.js @@ -8910,14 +8910,19 @@ Costume.prototype.rasterized = function () { }; Costume.prototype.pixels = function () { - var i, - pixels = [], - src = this.contents.getContext('2d').getImageData( - 0, - 0, - this.contents.width, - this.contents.height - ); + var pixels = [], + src, + i; + + if (!this.contents.width || !this.contents.height) { + return pixels; + } + src = this.contents.getContext('2d').getImageData( + 0, + 0, + this.contents.width, + this.contents.height + ); for (i = 0; i < src.data.length; i += 4) { pixels.push(new List([ src.data[i], diff --git a/src/threads.js b/src/threads.js index ff8a0686..1b6b7da5 100644 --- a/src/threads.js +++ b/src/threads.js @@ -4345,7 +4345,7 @@ Process.prototype.reportGetImageAttribute = function (choice, name) { this.blockReceiver().costumes.asArray(), function (c) {return c.name === name.toString(); } ) - ), + ) || new Costume(), option = this.inputOption(choice); switch (option) {