(svn r12249) [NoAI] -Fix: finally found why closing the game gave an assert() on running AIs noai
authortruebrain
Mon, 25 Feb 2008 14:34:16 +0000
branchnoai
changeset 9761 6c3e0f29a232
parent 9760 265fdd2130c3
child 9762 ad9c304c6c77
(svn r12249) [NoAI] -Fix: finally found why closing the game gave an assert() on running AIs
src/ai/ai_threads.cpp
--- a/src/ai/ai_threads.cpp	Mon Feb 25 14:03:14 2008 +0000
+++ b/src/ai/ai_threads.cpp	Mon Feb 25 14:34:16 2008 +0000
@@ -130,6 +130,8 @@
 			/* XXX -- It might be nice to throw an exception, as it is easier to handle */
 			//throw std::exception();
 			//NOT_REACHED();
+
+			main->SwitchToThis(RUNNING);
 			return;
 		}
 		assert(this->state == RUNNING);
@@ -315,8 +317,6 @@
 	/*virtual*/ ~AIThread_MT()
 	{
 		DEBUG(ai, 3, "-AIThread_MT(%d) from thr %u", this->fiber_id, ThreadObject::CurrentId());
-		bool wait_ok = this->thr->IsCurrent() ? true : this->thr->WaitForStop();
-		assert(wait_ok);
 		this->evt_go.Detach();
 	}
 
@@ -406,6 +406,8 @@
 		assert(cur->fiber_id == MAIN_THREAD);
 		assert(this->state == SUSPENDED);
 		this->SwitchToThis(STOPPING);
+		assert(this->state == SUSPENDED);
+		this->state = STOPPED;
 	}
 
 	/**
@@ -592,6 +594,8 @@
 		assert(cur->fiber_id == MAIN_THREAD);
 		assert(this->state == SUSPENDED);
 		this->SwitchToThis(STOPPING);
+		assert(this->state == SUSPENDED);
+		this->state = STOPPED;
 
 		this->DeleteFiber();
 	}