-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix texture memory leak #409
Conversation
rferrese
commented
Apr 16, 2019
- Change MaterialCacheData, MeshCacheData, and TextureCacheData to IDisposable
- Add ImageCache array to RefCountedCacheData
- Dont allow replacing arrays in RefCountedCacheData after construction to prevent leaks
- Prevent recreation of TextureCacheData (leaking references to cloned textures)
- Add debug asserts to texture reference setting to ensure no leaked references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good change. Thanks for fixing that memory leak.
{ | ||
TextureDefinition = texture | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this throw in the else case? Or warn or something? Or is it ok to silently do nothing on multiple calls to this function with the same textureIndex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really this entire method needs work. From what it looks like, this will fill in either ImageStreamCache or BufferCache depending on what type it is, but the IF statements dont make that intention clear. Both of these are guarded against multiple calls with the same ID. This also new's TextureCacheData, but that wasnt guarded (which was causing duplicate textures to be created). I'm not entirely sure why this function gets called multiple times, but subsequent calls with the same ID do in fact intend to populate with the same values.
As for your comment, this frequently gets called multiple times with the same ID, so a warning would probably not be the right thing to do in this case. If we rewrote this so that it only got called once per texture, I would be all for it. (similar to the debug asserts I added elsewhere)
UnityGLTF/Assets/UnityGLTF/Scripts/Cache/RefCountedCacheData.cs
Outdated
Show resolved
Hide resolved
Co-Authored-By: rferrese <[email protected]>