aboutsummaryrefslogtreecommitdiff
path: root/src/emerge.cpp
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2014-01-26 01:12:18 -0500
committerkwolekr <kwolekr@minetest.net>2014-01-26 01:12:18 -0500
commit9b978db0c2578b06c5669096e325c1ce70864edc (patch)
tree409944cd4d2ca5b95538bb70dc2168696cc1774b /src/emerge.cpp
parent6e352e3cbff7d4256657776a7dff828a43d948db (diff)
downloadminetest-9b978db0c2578b06c5669096e325c1ce70864edc.tar.gz
minetest-9b978db0c2578b06c5669096e325c1ce70864edc.tar.bz2
minetest-9b978db0c2578b06c5669096e325c1ce70864edc.zip
Fix use of previously deallocated EmergeManager
Diffstat (limited to 'src/emerge.cpp')
-rw-r--r--src/emerge.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/emerge.cpp b/src/emerge.cpp
index ff00a0b62..bd9b7c7bd 100644
--- a/src/emerge.cpp
+++ b/src/emerge.cpp
@@ -92,6 +92,11 @@ EmergeManager::EmergeManager(IGameDef *gamedef) {
this->biomedef = new BiomeDefManager();
this->params = NULL;
+ // Note that accesses to this variable are not synchronized.
+ // This is because the *only* thread ever starting or stopping
+ // EmergeThreads should be the ServerThread.
+ this->threads_active = false;
+
this->luaoverride_params = NULL;
this->luaoverride_params_modified = 0;
this->luaoverride_flagmask = 0;
@@ -128,9 +133,11 @@ EmergeManager::EmergeManager(IGameDef *gamedef) {
EmergeManager::~EmergeManager() {
for (unsigned int i = 0; i != emergethread.size(); i++) {
- emergethread[i]->Stop();
- emergethread[i]->qevent.signal();
- emergethread[i]->Wait();
+ if (threads_active) {
+ emergethread[i]->Stop();
+ emergethread[i]->qevent.signal();
+ emergethread[i]->Wait();
+ }
delete emergethread[i];
delete mapgen[i];
}
@@ -252,9 +259,32 @@ Mapgen *EmergeManager::getCurrentMapgen() {
}
-void EmergeManager::startAllThreads() {
+void EmergeManager::startThreads() {
+ if (threads_active)
+ return;
+
for (unsigned int i = 0; i != emergethread.size(); i++)
emergethread[i]->Start();
+
+ threads_active = true;
+}
+
+
+void EmergeManager::stopThreads() {
+ if (!threads_active)
+ return;
+
+ // Request thread stop in parallel
+ for (unsigned int i = 0; i != emergethread.size(); i++) {
+ emergethread[i]->Stop();
+ emergethread[i]->qevent.signal();
+ }
+
+ // Then do the waiting for each
+ for (unsigned int i = 0; i != emergethread.size(); i++)
+ emergethread[i]->Wait();
+
+ threads_active = false;
}