summaryrefslogtreecommitdiff
path: root/src/genworld.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-06-08 15:27:57 +0000
committerrubidium <rubidium@openttd.org>2008-06-08 15:27:57 +0000
commite43d0507301689d6178d310c98b1403588eb474f (patch)
tree376004aeb09d74a071fcdddcc61f01e9ea005d8b /src/genworld.cpp
parenteac3301b63070ad0c0f1ce1323f25326ce90226d (diff)
downloadopenttd-e43d0507301689d6178d310c98b1403588eb474f.tar.xz
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
Diffstat (limited to 'src/genworld.cpp')
-rw-r--r--src/genworld.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/genworld.cpp b/src/genworld.cpp
index 424750165..05e61b44a 100644
--- a/src/genworld.cpp
+++ b/src/genworld.cpp
@@ -156,7 +156,6 @@ static void _GenerateWorld(void *arg)
/* Show all vital windows again, because we have hidden them */
if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
_gw.active = false;
- _gw.thread = NULL;
_gw.proc = NULL;
_gw.threaded = false;
@@ -199,6 +198,7 @@ void WaitTillGeneratedWorld()
if (_gw.thread == NULL) return;
_gw.quit_thread = true;
_gw.thread->Join();
+ delete _gw.thread;
_gw.thread = NULL;
_gw.threaded = false;
}
@@ -233,9 +233,7 @@ void HandleGeneratingWorldAbortion()
/* Show all vital windows again, because we have hidden them */
if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
- ThreadObject *thread = _gw.thread;
_gw.active = false;
- _gw.thread = NULL;
_gw.proc = NULL;
_gw.abortp = NULL;
_gw.threaded = false;
@@ -243,7 +241,7 @@ void HandleGeneratingWorldAbortion()
DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
MarkWholeScreenDirty();
- thread->Exit();
+ _gw.thread->Exit();
}
/**
@@ -287,8 +285,14 @@ void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y)
/* Create toolbars */
SetupColorsAndInitialWindow();
+ if (_gw.thread != NULL) {
+ _gw.thread->Join();
+ delete _gw.thread;
+ _gw.thread = NULL;
+ }
+
if (_network_dedicated ||
- (_gw.thread = ThreadObject::New(&_GenerateWorld, NULL, &ThreadObject::TerminateCleanup)) == NULL) {
+ (_gw.thread = ThreadObject::New(&_GenerateWorld, NULL)) == NULL) {
DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode");
_gw.threaded = false;
_GenerateWorld(NULL);