Skip to content
Snippets Groups Projects
Unverified Commit b69851b3 authored by Marshall Quander's avatar Marshall Quander Committed by GitHub
Browse files

Merge pull request #448 from mozilla/gltf-cache-race

Fix a bug in GLTF cache
parents 342226ea 03d0b21a
No related branches found
No related tags found
No related merge requests found
...@@ -182,30 +182,15 @@ function nextTick() { ...@@ -182,30 +182,15 @@ function nextTick() {
} }
function cachedLoadGLTF(src, preferredTechnique, onProgress) { function cachedLoadGLTF(src, preferredTechnique, onProgress) {
return new Promise((resolve, reject) => { // Load the gltf model from the cache if it exists.
// Load the gltf model from the cache if it exists. if (!GLTFCache[src]) {
if (GLTFCache[src]) { GLTFCache[src] = new Promise((resolve, reject) => {
// Use a cloned copy of the cached model.
resolve(cloneGltf(GLTFCache[src]));
} else {
// Otherwise load the new gltf model.
const gltfLoader = new THREE.GLTFLoader(); const gltfLoader = new THREE.GLTFLoader();
gltfLoader.preferredTechnique = preferredTechnique; gltfLoader.preferredTechnique = preferredTechnique;
gltfLoader.load(src, resolve, onProgress, reject);
gltfLoader.load( });
src, }
model => { return GLTFCache[src].then(cloneGltf);
if (!GLTFCache[src]) {
// Store a cloned copy of the gltf model.
GLTFCache[src] = cloneGltf(model);
}
resolve(model);
},
onProgress,
reject
);
}
});
} }
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment