Stop threads of texture loading before destroying shader manager

This commit is contained in:
Benau 2018-03-12 09:21:30 +08:00
parent 48f2aa3da4
commit ffd6e84759
3 changed files with 16 additions and 10 deletions

View File

@ -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;

View File

@ -78,16 +78,7 @@ SPTextureManager::SPTextureManager()
// ----------------------------------------------------------------------------
SPTextureManager::~SPTextureManager()
{
m_max_threaded_load_obj.store(0);
std::unique_lock<std::mutex> 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)

View File

@ -85,6 +85,20 @@ public:
// ------------------------------------------------------------------------
~SPTextureManager();
// ------------------------------------------------------------------------
void stopThreads()
{
m_max_threaded_load_obj.store(0);
std::unique_lock<std::mutex> 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<bool()> threaded_function)