From dd50501e7324c37b7deb360e9d97a3ff3c8473c4 Mon Sep 17 00:00:00 2001 From: auria Date: Mon, 27 Sep 2010 15:46:24 +0000 Subject: [PATCH] More minor changes to make sure crashes don't occur due to the thread in the main screen git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@6156 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/states_screens/main_menu_screen.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 53ee7caa0..34418e492 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -95,6 +95,7 @@ void MainMenuScreen::changeNewsText(std::string action) } if(action == "offline") { + pthread_testcancel(); // check if thread was cancelled pthread_mutex_lock(&(this->m_mutex_news_text)); m_news_text = "offline"; pthread_mutex_unlock(&(this->m_mutex_news_text)); @@ -267,6 +268,12 @@ void * MainMenuScreen::downloadNews( void * pthis) void MainMenuScreen::tearDown() { fprintf(stdout, "canceling the thread\n"); + + // grab the mutex before returning to make sure the screen is not deleted while the thread is + // changing the text, which would result in weird results (tearDown does not automatically mean + // the screen is going to be destroyed but let's play on the safe side) + pthread_mutex_lock(&(this->m_mutex_news_text)); pthread_cancel(m_thread_news_text); + pthread_mutex_unlock(&(this->m_mutex_news_text)); } #endif