summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-09-17 17:25:42 +0200
committerjmoenig <jens@moenig.org>2013-09-17 17:25:42 +0200
commitc0a0c1f4a7a9f3cfd055288817530cf7c46bb26d (patch)
tree785cf1d7c7b51cce6453c7fec14d5742bf51b2b2 /objects.js
parent0947fbb80e6d4c57c63c588354e101a35bec087a (diff)
downloadsnap-c0a0c1f4a7a9f3cfd055288817530cf7c46bb26d.tar.gz
snap-c0a0c1f4a7a9f3cfd055288817530cf7c46bb26d.zip
fixed part of #154 - prevent costumes from being drawn while they are loading
prevents an occasional DOM error saying "an attempt was made to use an object that is not, or is no longer, usable" when loading a project that has costumes
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js20
1 files changed, 17 insertions, 3 deletions
diff --git a/objects.js b/objects.js
index f0d0e44..9e61d58 100644
--- a/objects.js
+++ b/objects.js
@@ -124,7 +124,7 @@ PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.objects = '2013-September-16';
+modules.objects = '2013-September-17';
var SpriteMorph;
var StageMorph;
@@ -1248,6 +1248,8 @@ SpriteMorph.prototype.drawNew = function () {
currentCenter = this.center(),
facing, // actual costume heading based on my rotation style
isFlipped,
+ isLoadingCostume = this.costume &&
+ typeof this.costume.loaded === 'function',
pic, // (flipped copy of) actual costume based on my rotation style
stageScale = this.parent instanceof StageMorph ?
this.parent.scale : 1,
@@ -1257,7 +1259,8 @@ SpriteMorph.prototype.drawNew = function () {
shift,
corner,
costumeExtent,
- ctx;
+ ctx,
+ handle;
if (this.isWarped) {
this.wantsRedraw = true;
@@ -1271,7 +1274,7 @@ SpriteMorph.prototype.drawNew = function () {
isFlipped = true;
}
}
- if (this.costume) {
+ if (this.costume && !isLoadingCostume) {
pic = isFlipped ? this.costume.flipped() : this.costume;
// determine the rotated costume's bounding box
@@ -1328,6 +1331,17 @@ SpriteMorph.prototype.drawNew = function () {
this.setCenter(currentCenter, true); // just me
SpriteMorph.uber.drawNew.call(this, facing);
this.rotationOffset = this.extent().divideBy(2);
+ if (isLoadingCostume) { // retry until costume is done loading
+ handle = setInterval(
+ function () {
+ myself.changed();
+ myself.drawNew();
+ myself.changed();
+ clearInterval(handle);
+ },
+ 100
+ );
+ }
}
this.version = Date.now();
};