Skip to content

Commit

Permalink
fix: promise order in layer compositor
Browse files Browse the repository at this point in the history
  • Loading branch information
bhouston committed Nov 9, 2020
1 parent 3072394 commit 207b899
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "threeify",
"version": "1.85.0",
"version": "1.86.0",
"description": "Typescript 3D Library loosely based on three.js",
"keywords": [
"threeify",
Expand Down
11 changes: 7 additions & 4 deletions src/lib/engines/layerCompositor/LayerCompositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ export class LayerCompositor {
loadTexImage2D(url: string, image: HTMLImageElement | ImageBitmap | undefined = undefined): Promise<TexImage2D> {
const layerImagePromise = this.texImage2DPromiseCache[url];
if (layerImagePromise !== undefined) {
console.log(`loading: ${url} (reusing promise)`);
return layerImagePromise;
}

return (this.texImage2DPromiseCache[url] = new Promise<TexImage2D>((resolve) => {
// check for texture in cache.
const layerImage = this.layerImageCache[url];
if (layerImage !== undefined) {
delete this.texImage2DPromiseCache[url];
return resolve(layerImage.texImage2D);
}

Expand All @@ -191,7 +191,7 @@ export class LayerCompositor {
texture.anisotropicLevels = 1;
texture.name = url;

// console.log(`loading: ${url}`);
console.log(`loading: ${url}`);
// load texture onto the GPU
const texImage2D = makeTexImage2DFromTexture(compositor.context, texture);
delete compositor.texImage2DPromiseCache[url];
Expand All @@ -205,14 +205,17 @@ export class LayerCompositor {
} else if (image instanceof HTMLImageElement || image instanceof ImageBitmap) {
return resolve(createTexture(this, image));
}
}));
})).then((texImage2D) => {
delete this.texImage2DPromiseCache[url];
return texImage2D;
});
}

discardTexImage2D(url: string): boolean {
// check for texture in cache.
const layerImage = this.layerImageCache[url];
if (layerImage !== undefined) {
// console.log(`discarding: ${url}`);
console.log(`discarding: ${url}`);
layerImage.dispose();
delete this.layerImageCache[url];
return true;
Expand Down

0 comments on commit 207b899

Please sign in to comment.