]> git.street.me.uk Git - andy/viking.git/commitdiff
Fix potential crashes from long running threads in a removed window.
authorRob Norris <rw_norris@hotmail.com>
Sat, 13 Dec 2014 12:57:09 +0000 (12:57 +0000)
committerRob Norris <rw_norris@hotmail.com>
Sun, 14 Dec 2014 17:20:29 +0000 (17:20 +0000)
src/viklayer.c
src/viklayerspanel.c
src/vikwindow.c

index 880c7394553c5b7140a2ee2e1fa759b1c2683249..c36306ac53976739223520a15a5edab3f0ad8d49 100644 (file)
@@ -93,10 +93,15 @@ static gboolean idle_draw ( VikLayer *vl )
 void vik_layer_emit_update ( VikLayer *vl )
 {
   if ( vl->visible && vl->realized ) {
+    GThread *thread = vik_window_get_thread ( VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl)) );
+    if ( !thread )
+      // Do nothing
+      return;
+
     vik_window_set_redraw_trigger(vl);
 
     // Only ever draw when there is time to do so
-    if ( g_thread_self() != vik_window_get_thread (VIK_WINDOW(VIK_GTK_WINDOW_FROM_LAYER(vl))) )
+    if ( g_thread_self() != thread )
       // Drawing requested from another (background) thread, so handle via the gdk thread method
       gdk_threads_add_idle ( (GSourceFunc) idle_draw, vl );
     else
index 5c9ef5b68d497dc15250e1fc9701aa638bf10d3a..96b0cbf7e289314ce24638cc2ced6db84fe195c4 100644 (file)
@@ -258,8 +258,13 @@ static gboolean idle_draw_panel ( VikLayersPanel *vlp )
 
 void vik_layers_panel_emit_update ( VikLayersPanel *vlp )
 {
+  GThread *thread = vik_window_get_thread (VIK_WINDOW(VIK_GTK_WINDOW_FROM_WIDGET(vlp)));
+  if ( !thread )
+    // Do nothing
+    return;
+
   // Only ever draw when there is time to do so
-  if ( g_thread_self() != vik_window_get_thread (VIK_WINDOW(VIK_GTK_WINDOW_FROM_WIDGET(vlp))) )
+  if ( g_thread_self() != thread )
     // Drawing requested from another (background) thread, so handle via the gdk thread method
     gdk_threads_add_idle ( (GSourceFunc) idle_draw_panel, vlp );
   else
index a4ee6a690d12a0a556ebcc5b972e1645a68ed534..4326afeb7a53b0f10fe3002760c4f769a4783f85 100644 (file)
@@ -305,12 +305,17 @@ static gboolean statusbar_idle_update ( statusbar_idle_data *sid )
  */
 void vik_window_statusbar_update ( VikWindow *vw, const gchar* message, vik_statusbar_type_t vs_type )
 {
+  GThread *thread = vik_window_get_thread ( vw );
+  if ( !thread )
+    // Do nothing
+    return;
+
   statusbar_idle_data *sid = g_malloc ( sizeof (statusbar_idle_data) );
   sid->vs = vw->viking_vs;
   sid->vs_type = vs_type;
   sid->message = g_strdup ( message );
 
-  if ( g_thread_self() == vik_window_get_thread ( vw ) ) {
+  if ( g_thread_self() == thread ) {
     g_idle_add ( (GSourceFunc) statusbar_idle_update, sid );
   }
   else {
@@ -4795,7 +4800,12 @@ gboolean vik_window_clear_highlight ( VikWindow *vw )
   return need_redraw;
 }
 
+/**
+ * May return NULL if the window no longer exists
+ */
 GThread *vik_window_get_thread ( VikWindow *vw )
 {
-  return vw->thread;
+  if ( vw )
+    return vw->thread;
+  return NULL;
 }