afritz1 / OpenTESArena

Open-source re-implementation of The Elder Scrolls: Arena.
MIT License
915 stars 68 forks source link

Texture manager refactor #184

Closed afritz1 closed 3 years ago

afritz1 commented 3 years ago

Re-designed the texture manager so it can fail to look-up a texture. Added native support for storing/handling 8-bit images and started using a new ID-based system for fast texture look-up.

Ran into some issues with dangling texture references if texture IDs are obtained after a texture reference look-up because the internal texture buffer in the texture manager might get resized, so just need to be careful by getting all texture IDs ahead of time. At least the texture look-up functions are const now.

afritz1 commented 3 years ago

Will be a little more important now to run sanitizers on the codebase before releases because of possible bugs like this but it's a net gain in the long run. I'm also a little confused how my old texture manager design never led to this same dangling texture reference bug. My best guess is that the std::unordered_map buckets had a small enough intersection with previously-obtained texture references in a certain scope that none of the buckets got re-allocated and caused bugs.