Fix crash when exiting server during running mapgen
authorsfan5 <sfan5@live.de>
Tue, 5 May 2020 18:19:47 +0000 (20:19 +0200)
committersfan5 <sfan5@live.de>
Tue, 5 May 2020 18:19:47 +0000 (20:19 +0200)
easily reproducible with a high num_emerge_threads and /emergeblocks

src/emerge.cpp

index 6e05a45c9df9e6c8acc176e10de22eac3365f6d3..a9fc0a4de84511d145090d1695fb35e421975821 100644 (file)
@@ -255,8 +255,9 @@ Mapgen *EmergeManager::getCurrentMapgen()
                return nullptr;
 
        for (u32 i = 0; i != m_threads.size(); i++) {
-               if (m_threads[i]->isCurrentThread())
-                       return m_threads[i]->m_mapgen;
+               EmergeThread *t = m_threads[i];
+               if (t->isRunning() && t->isCurrentThread())
+                       return t->m_mapgen;
        }
 
        return nullptr;
@@ -642,8 +643,7 @@ MapBlock *EmergeThread::finishGen(v3s16 pos, BlockMakeData *bmdata,
        /*
                Clear generate notifier events
        */
-       Mapgen *mg = m_emerge->getCurrentMapgen();
-       mg->gennotify.clearEvents();
+       m_mapgen->gennotify.clearEvents();
 
        EMERGE_DBG_OUT("ended up with: " << analyze_block(block));