(svn r13157) [NoAI] -Fix: in general it is considered VERY VERY VERY REALLY REALLY bad to delete a class instance from a function inside that class itself. noai
authortruebrain
Sun, 18 May 2008 11:25:04 +0000
branchnoai
changeset 10613 c1570be72d6c
parent 10514 8d9dbe82af3c
child 10620 3dfc77d25d66
(svn r13157) [NoAI] -Fix: in general it is considered VERY VERY VERY REALLY REALLY bad to delete a class instance from a function inside that class itself.
His surrounding is never informed of this 'action', and they all of a sudden have an invalid pointer, causing all kinds of cool and magic effects (read: random crashes all over the place).
It might be a REALLY good idea to leave cleaning up of a class instances to the creator of that instance.
If you want to cleanup the saveload thread, make a garbage collector. More things use threads (like fibers). Deleting a class like this is bad, worse, worst!!!! !! !!! !!!!! and should be avoided AT ALL COSTS!
src/thread_pthread.cpp
--- a/src/thread_pthread.cpp	Sun May 11 20:23:26 2008 +0000
+++ b/src/thread_pthread.cpp	Sun May 18 11:25:04 2008 +0000
@@ -104,8 +104,6 @@
 		pthread_join(m_thr, &ret);
 		m_thr = 0;
 
-		delete this;
-
 		return ret;
 	}
 
@@ -138,21 +136,15 @@
 		/* The new thread stops here so the calling thread can complete pthread_create() call */
 		sem_wait(&m_sem_start);
 
-		/* Did this thread die naturally/via exit, or did it join? */
-		bool exit = false;
-
 		/* Call the proc of the creator to continue this thread */
 		try {
 			m_proc(m_param);
 		} catch (...) {
-			exit = true;
 		}
 
 		/* Notify threads waiting for our completion */
 		sem_post(&m_sem_stop);
 
-		if (exit) delete this;
-
 		pthread_exit(NULL);
 	}
 };