Skip to content

Commit 8fe7723

Browse files
authored
Merge pull request #612 from guilhermesimoes/bugfix/memory-leak
Fix `freeTextureSource()` leaving stale entries in `textureSourceHashmap`
2 parents 461fe00 + 0df55f8 commit 8fe7723

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/tree/TextureManager.mjs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class TextureManager {
5353
for (let i = 0, n = this._uploadedTextureSources.length; i < n; i++) {
5454
this._nativeFreeTextureSource(this._uploadedTextureSources[i]);
5555
}
56-
56+
5757
this.textureSourceHashmap.clear();
5858
this._usedMemory = 0;
5959
}
@@ -95,7 +95,7 @@ export default class TextureManager {
9595
nativeTexture.update = this.stage.frameCounter;
9696

9797
this._uploadedTextureSources.push(textureSource);
98-
98+
9999
this.addToLookupMap(textureSource);
100100

101101
// add VRAM tracking if using the webgl renderer
@@ -140,7 +140,7 @@ export default class TextureManager {
140140
gc() {
141141
this.freeUnusedTextureSources();
142142
}
143-
143+
144144
freeUnusedTextureSources() {
145145
let remainingTextureSources = [];
146146
for (let i = 0, n = this._uploadedTextureSources.length; i < n; i++) {
@@ -190,11 +190,14 @@ export default class TextureManager {
190190
if (textureSource.isLoaded()) {
191191
if (managed) {
192192
this._addMemoryUsage(-textureSource.w * textureSource.h);
193+
this._updateVramUsage(textureSource, -1);
193194
this._uploadedTextureSources.splice(index, 1);
194195
}
195196
this._nativeFreeTextureSource(textureSource);
196197
}
197198

199+
this.textureSourceHashmap.delete(textureSource.lookupId);
200+
198201
// Should be reloaded.
199202
textureSource.loadingSince = null;
200203
}

0 commit comments

Comments
 (0)