From 7966422582fb184e877bba6c8f9c3b2173b112ca Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 18 May 2013 05:57:22 +0000 Subject: [PATCH] attempt to fix segfaults discovered during testing --- source/g3d_viewer/main.cpp | 1 - source/glest_game/menu/main_menu.cpp | 3 --- source/glest_game/network/server_interface.cpp | 7 ++++++- source/glest_map_editor/main.cpp | 1 - .../shared_lib/sources/platform/common/base_thread.cpp | 2 +- .../sources/platform/common/simple_threads.cpp | 4 ++-- source/shared_lib/sources/platform/posix/ircclient.cpp | 1 - .../sources/platform/posix/miniftpclient.cpp | 1 - source/shared_lib/sources/platform/sdl/thread.cpp | 10 +++++----- 9 files changed, 14 insertions(+), 16 deletions(-) diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 54ae3fca..d6240979 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -728,7 +728,6 @@ void MainWindow::onClose(wxCloseEvent &event){ if(glCanvas) glCanvas->Destroy(); glCanvas = NULL; - //delete this; this->Destroy(); } diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index 479ff957..1f01e471 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -248,9 +248,6 @@ void MainMenu::setState(MenuState *newstate) { //printf("In MainMenu::setState() #1\n"); - //delete this->state; - //this->state = newstate; - if(oldstate != NULL && oldstate != newstate) { MenuState *oldstatePtr = oldstate; delete oldstate; diff --git a/source/glest_game/network/server_interface.cpp b/source/glest_game/network/server_interface.cpp index cdffd7c6..d22d0e58 100644 --- a/source/glest_game/network/server_interface.cpp +++ b/source/glest_game/network/server_interface.cpp @@ -1784,6 +1784,8 @@ void ServerInterface::waitUntilReady(Checksum *checksum) { MAX_LOOP_COUNT_BEFORE_SLEEP = Config::getInstance().getInt("NetworkServerLoopGameLoadingCap",intToStr(MAX_LOOP_COUNT_BEFORE_SLEEP).c_str()); int sleepMillis = Config::getInstance().getInt("NetworkServerLoopGameLoadingCapSleepMillis","10"); + int64 lastStatusUpdate = 0; + while(exitServer == false && allReady == false && logger.getCancelLoading() == false) { waitLoopIterationCount++; if(waitLoopIterationCount > 0 && waitLoopIterationCount % MAX_LOOP_COUNT_BEFORE_SLEEP == 0) { @@ -1844,7 +1846,10 @@ void ServerInterface::waitUntilReady(Checksum *checksum) { return; } else { - if(chrono.getMillis() % 100 == 0) { + //if(chrono.getMillis() % 100 == 0) { + if(chrono.getMillis() - lastStatusUpdate > 200) { + lastStatusUpdate = chrono.getMillis(); + string waitForHosts = ""; for(int i = 0; i < waitingForHosts.size(); i++) { if(waitForHosts != "") { diff --git a/source/glest_map_editor/main.cpp b/source/glest_map_editor/main.cpp index fa0488c7..8cbdb44c 100644 --- a/source/glest_map_editor/main.cpp +++ b/source/glest_map_editor/main.cpp @@ -445,7 +445,6 @@ void MainWindow::onClose(wxCloseEvent &event) { if(glCanvas) glCanvas->Destroy(); glCanvas = NULL; - //delete this; this->Destroy(); } diff --git a/source/shared_lib/sources/platform/common/base_thread.cpp b/source/shared_lib/sources/platform/common/base_thread.cpp index 7bfc3a84..add1dd15 100644 --- a/source/shared_lib/sources/platform/common/base_thread.cpp +++ b/source/shared_lib/sources/platform/common/base_thread.cpp @@ -238,7 +238,7 @@ void BaseThread::setDeleteSelfOnExecutionDone(bool value) { void BaseThread::deleteSelfIfRequired() { if(getDeleteSelfOnExecutionDone() == true) { if(isThreadDeleted(this->ptr) == false) { - delete this; + this->setDeleteAfterExecute(true); } return; } diff --git a/source/shared_lib/sources/platform/common/simple_threads.cpp b/source/shared_lib/sources/platform/common/simple_threads.cpp index 07354442..52868fba 100644 --- a/source/shared_lib/sources/platform/common/simple_threads.cpp +++ b/source/shared_lib/sources/platform/common/simple_threads.cpp @@ -495,7 +495,7 @@ void SimpleTaskThread::execute() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(isThreadDeleted(ptr_cpy) == false) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); - delete this; + this->setDeleteAfterExecute(true); } return; } @@ -608,7 +608,7 @@ void LogFileThread::execute() { if(mustDeleteSelf == true) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] LogFile thread is deleting self\n",__FILE__,__FUNCTION__,__LINE__); if(isThreadDeleted(ptr_cpy) == false) { - delete this; + this->setDeleteAfterExecute(true); } return; } diff --git a/source/shared_lib/sources/platform/posix/ircclient.cpp b/source/shared_lib/sources/platform/posix/ircclient.cpp index f4db9d22..70c35b35 100644 --- a/source/shared_lib/sources/platform/posix/ircclient.cpp +++ b/source/shared_lib/sources/platform/posix/ircclient.cpp @@ -855,7 +855,6 @@ void IRCThread::execute() { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In IRCThread() calling delete ...\n"); //printf("In ~IRCThread Line: %d [%p]\n",__LINE__,this); - //delete this; setDeleteAfterExecute(true); } diff --git a/source/shared_lib/sources/platform/posix/miniftpclient.cpp b/source/shared_lib/sources/platform/posix/miniftpclient.cpp index f6c2209d..d62e5d94 100644 --- a/source/shared_lib/sources/platform/posix/miniftpclient.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpclient.cpp @@ -1214,7 +1214,6 @@ void FTPClientThread::execute() { // Delete ourself when the thread is done (no other actions can happen after this // such as the mutex which modifies the running status of this method - //delete this; deleteSelfIfRequired(); } diff --git a/source/shared_lib/sources/platform/sdl/thread.cpp b/source/shared_lib/sources/platform/sdl/thread.cpp index 612666a7..ce4f298f 100644 --- a/source/shared_lib/sources/platform/sdl/thread.cpp +++ b/source/shared_lib/sources/platform/sdl/thread.cpp @@ -30,7 +30,7 @@ vector Thread::threadList; auto_ptr Mutex::mutexMutexList(new Mutex(CODE_AT_LINE)); vector Mutex::mutexList; -class ThreadAutoCleanup : public BaseThread +class ThreadGarbageCollector : public BaseThread { protected: Mutex mutexPendingCleanupList; @@ -48,10 +48,10 @@ protected: return false; } public: - ThreadAutoCleanup() : BaseThread() { + ThreadGarbageCollector() : BaseThread() { removeThreadFromList(); } - virtual ~ThreadAutoCleanup() { + virtual ~ThreadGarbageCollector() { //printf("In ~ThreadAutoCleanup Line: %d\n",__LINE__); } virtual void execute() { @@ -72,7 +72,7 @@ public: } }; -static auto_ptr cleanupThread; +static auto_ptr cleanupThread; // ===================================== // Threads // ===================================== @@ -194,7 +194,7 @@ void Thread::queueAutoCleanThread() { if(cleanupThread.get() == NULL) { //printf("In Thread::shutdownThreads Line: %d\n",__LINE__); - cleanupThread.reset(new ThreadAutoCleanup()); + cleanupThread.reset(new ThreadGarbageCollector()); cleanupThread->start(); sleep(0); }