Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/core/a-assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ class AAssets extends ANode {
loaded.push(new Promise(function (resolve, reject) {
// Set in cache because we won't be needing to call three.js loader if we have.
// a loaded media element.
THREE.Cache.add('image:' + imgEls[i].getAttribute('src'), imgEl);
if (imgEl.complete) {
THREE.Cache.add('image:' + imgEls[i].getAttribute('src'), imgEl);
resolve();
return;
}
imgEl.onload = resolve;
imgEl.onload = function () {
THREE.Cache.add('image:' + imgEls[i].getAttribute('src'), imgEl);
resolve();
};
imgEl.onerror = reject;
}));
}
Expand Down
16 changes: 10 additions & 6 deletions tests/components/material.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,20 @@ suite('material', function () {
THREE.Cache.clear();
assetsEl.appendChild(img);
el.sceneEl.appendChild(assetsEl);
// Adding the asset will add image:${IMG_SRC} in THREE.Cache.files
// without going through THREE.ImageLoader
// Adding the asset will add image:${IMG_SRC} in THREE.Cache when the img
// loading is complete with img.onload, without going through THREE.ImageLoader
assert.notOk(!!THREE.Cache.get(`image:${IMG_SRC}`));
el.addEventListener('materialtextureloaded', function () {
assert.notOk(imageLoaderSpy.called);
assert.notOk(textureLoaderSpy.called);
assert.ok(`image:${IMG_SRC}` in THREE.Cache.files);
THREE.Cache.clear();
THREE.ImageLoader.prototype.load.restore();
THREE.TextureLoader.prototype.load.restore();
done();
// load event is triggered after this materialtextureloaded callback
img.addEventListener('load', function () {
assert.equal(THREE.Cache.get(`image:${IMG_SRC}`), img);
THREE.Cache.clear();
done();
}, {once: true});
});
el.setAttribute('material', 'src', '#foo');
});
Expand All @@ -194,7 +198,7 @@ suite('material', function () {
var imageLoaderSpy = this.sinon.spy(THREE.ImageLoader.prototype, 'load');
el.addEventListener('materialtextureloaded', function () {
assert.ok(imageLoaderSpy.called);
assert.ok(`image:${IMG_SRC}` in THREE.Cache.files);
assert.ok(!!THREE.Cache.get(`image:${IMG_SRC}`));
THREE.ImageLoader.prototype.load.restore();
done();
});
Expand Down
2 changes: 1 addition & 1 deletion tests/components/sound.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import THREE from 'lib/three.js';
suite('sound', function () {
setup(function (done) {
var el = this.el = entityFactory();
THREE.Cache.files = {};
THREE.Cache.clear();
setTimeout(() => {
el.setAttribute('sound', {
autoplay: true,
Expand Down
4 changes: 2 additions & 2 deletions tests/core/a-assets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ suite('a-assets', function () {
done();
});
document.body.appendChild(scene);
THREE.Cache.files = {};
THREE.Cache.clear();
});

test('loads even if one asset fails to load', function (done) {
Expand Down Expand Up @@ -81,7 +81,7 @@ suite('a-assets', function () {
assetsEl.appendChild(img);

img.addEventListener('load', function () {
assert.equal(THREE.Cache.files[`image:${IMG_SRC}`], img);
assert.equal(THREE.Cache.get(`image:${IMG_SRC}`), img);
done();
});

Expand Down