[gimp] app: use a weak pointer for tool-manager active group



commit 30d833d00f2fd10480e8bf3542ea3c26004e7b73
Author: Ell <ell_se yahoo com>
Date:   Sat Feb 1 12:41:11 2020 +0200

    app: use a weak pointer for tool-manager active group
    
    In GimpToolManager, use a weak pointer for tracking the active tool
    group, instead of taking a reference on it.  This avoids
    erroneously extending the group's lifetime, which can cause
    problems with the tool-item hierarchy.
    
    In GimpToolGroup, make sure that newly-added tools don't already
    have a parent.

 app/core/gimptoolgroup.c | 3 +++
 app/tools/tool_manager.c | 2 +-
 2 files changed, 4 insertions(+), 1 deletion(-)
---
diff --git a/app/core/gimptoolgroup.c b/app/core/gimptoolgroup.c
index b9a412ee68..31d91b93f5 100644
--- a/app/core/gimptoolgroup.c
+++ b/app/core/gimptoolgroup.c
@@ -287,6 +287,9 @@ gimp_tool_group_child_add (GimpContainer *container,
                            GimpToolInfo  *tool_info,
                            GimpToolGroup *tool_group)
 {
+  g_return_if_fail (
+    gimp_viewable_get_parent (GIMP_VIEWABLE (tool_info)) == NULL);
+
   gimp_viewable_set_parent (GIMP_VIEWABLE (tool_info),
                             GIMP_VIEWABLE (tool_group));
 
diff --git a/app/tools/tool_manager.c b/app/tools/tool_manager.c
index 9de93f6654..296606a70e 100644
--- a/app/tools/tool_manager.c
+++ b/app/tools/tool_manager.c
@@ -659,7 +659,7 @@ tool_manager_set_active_tool_group (GimpToolManager *tool_manager,
             tool_manager);
         }
 
-      g_set_object (&tool_manager->active_tool_group, tool_group);
+      g_set_weak_pointer (&tool_manager->active_tool_group, tool_group);
 
       if (tool_manager->active_tool_group)
         {


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