[gimp] app: fix sending signals to finalized object.



commit 68dcb4b4213071b141d9a01fdfd49475ad7a931a
Author: Jehan <jehan girinstud io>
Date:   Wed Apr 21 14:14:36 2021 +0200

    app: fix sending signals to finalized object.
    
    Fixing:
    
    > GLib-GObject-WARNING **: 01:43:13.747: instance with invalid (NULL) class pointer
    > GLib-GObject-CRITICAL **: 14:15:37.327: g_signal_emit_valist: assertion 'G_TYPE_CHECK_INSTANCE 
(instance)' failed
    
    When changing brushes through tool options. Thanks to ankh for noticing
    this.

 app/widgets/gimpcontainerview.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/app/widgets/gimpcontainerview.c b/app/widgets/gimpcontainerview.c
index 8843bfa4ab..e6bbed0e4d 100644
--- a/app/widgets/gimpcontainerview.c
+++ b/app/widgets/gimpcontainerview.c
@@ -841,6 +841,12 @@ gimp_container_view_multi_selected (GimpContainerView *view,
 
   selected_count = g_list_length (items);
 
+  /* For some types of transient containers, the fact of setting the
+   * context makes the container disappear (i.e. the object is
+   * destroyed). So we add a weak pointer to not send a signal to a dead
+   * reference later.
+   */
+  g_object_add_weak_pointer (G_OBJECT (view), (gpointer) &view);
   if (selected_count == 1)
     {
       GimpContainerViewPrivate *private = GIMP_CONTAINER_VIEW_GET_PRIVATE (view);
@@ -861,10 +867,15 @@ gimp_container_view_multi_selected (GimpContainerView *view,
             }
         }
     }
-  if (selected_count > 0)
+
+  if (view)
     {
-      g_signal_emit (view, view_signals[SELECT_ITEMS], 0,
-                     items, items_data, &success);
+      if (selected_count > 0)
+        {
+          g_signal_emit (view, view_signals[SELECT_ITEMS], 0,
+                         items, items_data, &success);
+        }
+      g_object_remove_weak_pointer (G_OBJECT (view), (gpointer) &view);
     }
 
   return success;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]