wowdev/noggit3

swapping textures crashes if replaced texture was last reference

bloerwald opened this issue · 2 comments

If the replaced texture is the last instance of that texture, it will be erased within the slot, leading to a glDeleteTextures() without active context.

VCRUNTIME140                                  CxxThrowException
opengl\context.cpp (57)                       opengl::`anonymous namespace'::verify_context_and_check_for_gl_errors::verify_context_and_check_for_gl_errors
opengl\context.cpp (285)                      opengl::context::deleteTextures
opengl\texture.cpp (20)                       opengl::texture::~texture
                                              std::map<std::string,blp_texture>::_Erase_unchecked
noggit\multimap_with_normalized_key.hpp (89)  noggit::async_object_multimap_with_normalized_key<blp_texture>::erase
Qt5Core                                       QtPrivate::QFunctorSlotObject<<lambda_1f883b93a2eca3bd8ea76fc535a6773d>,0,QtPrivate::List<>,void>::impl
Qt5Core                                       QMetaObject::activate
Qt5Widgets                                    QAbstractButton::clicked

Also when clicking Select. tldr: check all buttons for context. tlldr: we should lazily delete textures in the next render loop instead of directly.

#58 and #12 are similar.
in recent years a pattern in (multithreaded) engines has emerged where gpu commands are collected in different threads (command buffers) and are then submitted to the gpu as batches in one or multiple render threads.
something along those lines would avoid all situations where currently makeCurrent() is called. big change tho.