From 6299c6ef046ff3d845fc0fdefa96a2496fd4fdb1 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 17 Oct 2014 11:23:01 +0200 Subject: Fix GUI crash when running in thread mode and init wasn't done when show was called. --- plugingui/plugingui.cc | 24 ++++++------------------ plugingui/plugingui.h | 1 + 2 files changed, 7 insertions(+), 18 deletions(-) (limited to 'plugingui') diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index 4a2f4fa..5408334 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -172,7 +172,6 @@ PluginGUI::PluginGUI() : MessageReceiver(MSGRCV_UI), sem("plugingui") { initialised = false; - //printf("PluginGUI::PluginGUI() begin\n"); fflush(stdout); windowClosedHandler = NULL; changeMidimapHandler = NULL; @@ -189,8 +188,6 @@ PluginGUI::PluginGUI() #endif/*USE_THREAD*/ sem.wait(); - - //printf("PluginGUI::PluginGUI() done\n"); fflush(stdout); } PluginGUI::~PluginGUI() @@ -306,8 +303,6 @@ void PluginGUI::init() { DEBUG(gui, "init"); - //printf("init begin\n"); fflush(stdout); - config = new Config(); config->load(); @@ -472,16 +467,13 @@ void PluginGUI::init() sem.post(); - //printf("init end\n"); fflush(stdout); initialised = true; } void PluginGUI::show() { - while(!initialised) { - //printf("Waiting for init to finish\n"); fflush(stdout); - sleep(1); - } + while(!initialised) usleep(10000); + if(!window) init(); window->show(); @@ -489,19 +481,15 @@ void PluginGUI::show() void PluginGUI::hide() { - while(!initialised) { - //printf("Waiting for init to finish\n"); fflush(stdout); - sleep(1); - } + while(!initialised) usleep(10000); + if(window) window->hide(); } void PluginGUI::processEvents() { - if(!initialised) { - //printf("Not yet initialised\n"); fflush(stdout); - return; - } + if(!initialised) return; + if(closing) { if(windowClosedHandler) windowClosedHandler(windowClosedPtr); closing = false; diff --git a/plugingui/plugingui.h b/plugingui/plugingui.h index 36e8b1c..39643e1 100644 --- a/plugingui/plugingui.h +++ b/plugingui/plugingui.h @@ -93,6 +93,7 @@ private: volatile bool running; volatile bool closing; volatile bool initialised; + Semaphore sem; }; -- cgit v1.2.3