Add image load onerror handler

Make sure, when loading from json, that
a bad image path doesn't fail the desserialization

Signed-off-by: kangax <kangax@gmail.com>
This commit is contained in:
Josh Pearce 2013-01-04 12:15:25 -05:00 committed by kangax
parent dc2e5210ae
commit d56bf59137
2 changed files with 13 additions and 4 deletions

View file

@ -352,8 +352,15 @@
var instance = new fabric.Image(img, object);
callback && callback(instance);
img = img.onload = null;
};
img = img.onload = img.onerror = null;
};
/** @ignore */
img.onerror = function(e) {
fabric.log('Error loading ' + img.src);
callback && callback(null, true);
img = img.onload = img.onerror = null;
};
img.src = src;
};

View file

@ -223,8 +223,10 @@
}
var klass = getKlass(o.type);
if (klass.async) {
klass.fromObject(o, function (o) {
enlivenedObjects[index] = o;
klass.fromObject(o, function (o, error) {
if (!error) {
enlivenedObjects[index] = o;
}
onLoaded();
});
}