Fix freeTextureSource() leaving stale entries in textureSourceHashmap - #612
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
There was a problem hiding this comment.
Pull request overview
This PR fixes a memory leak in the texture source reuse cache by ensuring freeTextureSource() removes freed texture sources from textureSourceHashmap, matching the cleanup behavior already performed during gc().
Changes:
- Remove stale
textureSourceHashmapentries whenfreeTextureSource()is called. - Minor whitespace cleanup in
TextureManager.mjs.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I have read the CLA Document and I hereby sign the CLA |
b4edc48 to
b6f9056
Compare
b6f9056 to
3b53a24
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/tree/TextureManager.mjs:199
- When freeing a loaded texture source, VRAM usage is incremented in
uploadTextureSource()via_updateVramUsage(textureSource, 1), butfreeTextureSource()never decrements it. This can leaveStage.usedVram*stats stale (only increasing) after manual frees / source replacement.
Call _updateVramUsage(textureSource, -1) before _nativeFreeTextureSource() (it needs textureSource.nativeTexture to still be present).
this._nativeFreeTextureSource(textureSource);
}
this.textureSourceHashmap.delete(textureSource.lookupId);
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/tree/TextureManager.mjs:198
freeTextureSource()deletes fromtextureSourceHashmappurely bylookupId. If the samelookupIdhas been re-associated to a differentTextureSource(e.g., after a cleanup/reload), this will remove the wrong entry. Guard against falsy ids and only delete when the map currently points to the instance being freed.
this.textureSourceHashmap.delete(textureSource.lookupId);
src/tree/TextureManager.mjs:195
freeTextureSource()updates_usedMemoryfor managed textures but does not update VRAM usage counters, unlike_freeManagedTextureSource(). This will leaveStage.usedVram*overstated when textures are freed manually or on replacement.
if (managed) {
this._addMemoryUsage(-textureSource.w * textureSource.h);
this._uploadedTextureSources.splice(index, 1);
}
this._nativeFreeTextureSource(textureSource);
When
gc()is called, it callsfreeUnusedTextureSources, which at the end calls_cleanupLookupMap, cleaning up all unused texture sources fromtextureSourceHashmap.However, when
freeTextureSourceis called (either when a texture source is replaced or when someone manually callstexture.free()), the stale texture source is kept insidetextureSourceHashmap, leading to a memory leak.This issue was detected because we use a single text texture for subtitles, and keep changing the text of that texture as playback progresses.