src/genworld.cpp
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
--- a/src/genworld.cpp	Tue Jun 17 10:32:49 2008 +0000
+++ b/src/genworld.cpp	Tue Jun 17 13:22:13 2008 +0000
@@ -156,7 +156,6 @@
 		/* 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 @@
 	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 @@
 	/* 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 @@
 	DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
 	MarkWholeScreenDirty();
 
-	thread->Exit();
+	_gw.thread->Exit();
 }
 
 /**
@@ -287,6 +285,12 @@
 	/* 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)) == NULL) {
 		DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode");