diff --git a/src/graphics/sp/sp_base.cpp b/src/graphics/sp/sp_base.cpp index 75cb66480..c1514061a 100644 --- a/src/graphics/sp/sp_base.cpp +++ b/src/graphics/sp/sp_base.cpp @@ -574,6 +574,7 @@ void init() void destroy() { g_dy_dc.clear(); + SPTextureManager::get()->stopThreads(); SPShaderManager::destroy(); g_glow_shader = NULL; g_normal_visualizer = NULL; diff --git a/src/graphics/sp/sp_texture_manager.cpp b/src/graphics/sp/sp_texture_manager.cpp index fbd955fa3..24281efde 100644 --- a/src/graphics/sp/sp_texture_manager.cpp +++ b/src/graphics/sp/sp_texture_manager.cpp @@ -78,16 +78,7 @@ SPTextureManager::SPTextureManager() // ---------------------------------------------------------------------------- SPTextureManager::~SPTextureManager() { - m_max_threaded_load_obj.store(0); - std::unique_lock ul(m_thread_obj_mutex); - m_threaded_functions.push_back([](){ return true; }); - m_thread_obj_cv.notify_all(); - ul.unlock(); - for (std::thread& t : m_threaded_load_obj) - { - t.join(); - } - m_threaded_load_obj.clear(); + assert(m_threaded_load_obj.empty()); removeUnusedTextures(); #ifdef DEBUG for (auto p : m_textures) diff --git a/src/graphics/sp/sp_texture_manager.hpp b/src/graphics/sp/sp_texture_manager.hpp index 25efa2c1a..685803fe5 100644 --- a/src/graphics/sp/sp_texture_manager.hpp +++ b/src/graphics/sp/sp_texture_manager.hpp @@ -85,6 +85,20 @@ public: // ------------------------------------------------------------------------ ~SPTextureManager(); // ------------------------------------------------------------------------ + void stopThreads() + { + m_max_threaded_load_obj.store(0); + std::unique_lock ul(m_thread_obj_mutex); + m_threaded_functions.push_back([](){ return true; }); + m_thread_obj_cv.notify_all(); + ul.unlock(); + for (std::thread& t : m_threaded_load_obj) + { + t.join(); + } + m_threaded_load_obj.clear(); + } + // ------------------------------------------------------------------------ void removeUnusedTextures(); // ------------------------------------------------------------------------ void addThreadedFunction(std::function threaded_function)