[glom] Relationships Overview: Maybe fix a hang/crash.



commit be3f0de3d026074bda6ab7ed1694940fcbcc61de
Author: Murray Cumming <murrayc murrayc com>
Date:   Sun Jan 31 18:08:06 2010 +0100

    Relationships Overview: Maybe fix a hang/crash.
    
    	* glom/mode_design/relationships_overview/dialog_relationships_overview.[h|cc]:
    	Signal handlers: Take sigc::bind() RefPtr parameters by value instead of by
    	const &, to avoid having to use sigc::ref() or worry if it works.
    	Save sigc::connections in a list so we can disconnect signal handlers when
    	deleting items bound with sigc::bind(). Do this in the destructor too, which
    	seems to fix the valgrind errors in bug #594737, though not the
    	"instance of invalid non-instantiatable type" warning.

 ChangeLog                                          |   12 +++++
 .../dialog_relationships_overview.cc               |   47 +++++++++++++++----
 .../dialog_relationships_overview.h                |   11 +++--
 3 files changed, 56 insertions(+), 14 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 8117849..af135eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2010-01-31  Murray Cumming  <murrayc murrayc com>
+
+  Relationships Overview: Maybe fix a hang/crash.
+    
+  * glom/mode_design/relationships_overview/dialog_relationships_overview.[h|cc]:
+  Signal handlers: Take sigc::bind() RefPtr parameters by value instead of by
+  const &, to avoid having to use sigc::ref() or worry if it works.
+  Save sigc::connections in a list so we can disconnect signal handlers when
+  deleting items bound with sigc::bind(). Do this in the destructor too, which
+  seems to fix the valgrind errors in bug #594737, though not the
+  instance of invalid non-instantiatable type" warning.
+    	
 2010-01-27  Michael Hasselmann  <michaelh openismus com>
 
 	Fixed the parser to perform stateless async file operations
diff --git a/glom/mode_design/relationships_overview/dialog_relationships_overview.cc b/glom/mode_design/relationships_overview/dialog_relationships_overview.cc
index 8624bd2..6a19ec9 100644
--- a/glom/mode_design/relationships_overview/dialog_relationships_overview.cc
+++ b/glom/mode_design/relationships_overview/dialog_relationships_overview.cc
@@ -149,11 +149,35 @@ Dialog_RelationshipsOverview::Dialog_RelationshipsOverview(BaseObjectType* cobje
 Dialog_RelationshipsOverview::~Dialog_RelationshipsOverview()
 {
   get_size(m_last_size_x, m_last_size_y);
+  
+  //Disconnect signal handlers for all current items, 
+  //so sigc::bind()ed RefPtrs can be released.
+  while(m_list_table_connections.size())
+  {
+     type_list_connections::iterator iter = m_list_table_connections.begin();
+     sigc::connection the_connection = *iter;
+     the_connection.disconnect();
+     m_list_table_connections.erase(iter);
+  }
+  
+  //Remove all current items:
+  //while(m_group_tables->get_n_children() > 0)
+  //  m_group_tables->remove_child(0);
 }
 
 
 void Dialog_RelationshipsOverview::draw_tables()
 {
+  //Disconnect signal handlers for all current items, 
+  //so sigc::bind()ed RefPtrs can be released.
+  while(m_list_table_connections.size())
+  {
+     type_list_connections::iterator iter = m_list_table_connections.begin();
+     sigc::connection the_connection = *iter;
+     the_connection.disconnect();
+     m_list_table_connections.erase(iter);
+  }
+  
   //Remove all current items:
   while(m_group_tables->get_n_children() > 0)
     m_group_tables->remove_child(0);
@@ -189,12 +213,15 @@ void Dialog_RelationshipsOverview::draw_tables()
         CanvasGroupDbTable::create(info->get_name(), info->get_title_or_name(), fields, table_x, table_y);
       m_group_tables->add_child(table_group);
 
-      table_group->signal_moved().connect( sigc::bind(
-         sigc::mem_fun(*this, &Dialog_RelationshipsOverview::on_table_moved),
-         table_group) );
-      table_group->signal_show_context().connect( sigc::bind(
-         sigc::mem_fun(*this, &Dialog_RelationshipsOverview::on_table_show_context),
-         table_group) );
+      sigc::connection the_connection = table_group->signal_moved().connect( sigc::bind(
+        sigc::mem_fun(*this, &Dialog_RelationshipsOverview::on_table_moved),
+        table_group) );
+      m_list_table_connections.push_back(the_connection);
+     
+      the_connection = table_group->signal_show_context().connect( sigc::bind(
+        sigc::mem_fun(*this, &Dialog_RelationshipsOverview::on_table_show_context),
+        table_group) );
+      m_list_table_connections.push_back(the_connection);
     
       //tv->x2 = tv->x1 + table_width;
       //tv->y2 = tv->y1 + table_height;
@@ -414,7 +441,7 @@ Glib::RefPtr<CanvasGroupDbTable> Dialog_RelationshipsOverview::get_table_group(c
   return Glib::RefPtr<CanvasGroupDbTable>();
 }
 
-void Dialog_RelationshipsOverview::on_table_moved(const Glib::RefPtr<CanvasGroupDbTable>& table)
+void Dialog_RelationshipsOverview::on_table_moved(Glib::RefPtr<CanvasGroupDbTable> table)
 {
   Document* document = dynamic_cast<Document*>(get_document());
   if(document && table)
@@ -432,7 +459,7 @@ void Dialog_RelationshipsOverview::on_table_moved(const Glib::RefPtr<CanvasGroup
   draw_lines();
 }
 
-void Dialog_RelationshipsOverview::on_table_show_context(guint button, guint32 activate_time, const Glib::RefPtr<CanvasGroupDbTable>& table)
+void Dialog_RelationshipsOverview::on_table_show_context(guint button, guint32 activate_time, Glib::RefPtr<CanvasGroupDbTable> table)
 {
   if(m_action_edit_fields)
   {
@@ -499,7 +526,7 @@ void Dialog_RelationshipsOverview::setup_context_menu()
   m_context_menu = dynamic_cast<Gtk::Menu*>( m_context_menu_uimanager->get_widget("/ContextMenu") ); 
 }
 
-void Dialog_RelationshipsOverview::on_context_menu_edit_fields(const Glib::RefPtr<CanvasGroupDbTable>& table)
+void Dialog_RelationshipsOverview::on_context_menu_edit_fields(Glib::RefPtr<CanvasGroupDbTable> table)
 {
   App_Glom* pApp = App_Glom::get_application();
   if(pApp && table)
@@ -510,7 +537,7 @@ void Dialog_RelationshipsOverview::on_context_menu_edit_fields(const Glib::RefPt
   }
 }
 
-void Dialog_RelationshipsOverview::on_context_menu_edit_relationships(const Glib::RefPtr<CanvasGroupDbTable>& table)
+void Dialog_RelationshipsOverview::on_context_menu_edit_relationships(Glib::RefPtr<CanvasGroupDbTable> table)
 {
   App_Glom* pApp = App_Glom::get_application();
   if(pApp && table)
diff --git a/glom/mode_design/relationships_overview/dialog_relationships_overview.h b/glom/mode_design/relationships_overview/dialog_relationships_overview.h
index 0909120..b8d5a47 100644
--- a/glom/mode_design/relationships_overview/dialog_relationships_overview.h
+++ b/glom/mode_design/relationships_overview/dialog_relationships_overview.h
@@ -66,11 +66,11 @@ private:
   void on_menu_file_save();
   void on_menu_view_showgrid();
 
-  void on_table_moved(const Glib::RefPtr<CanvasGroupDbTable>& table);
-  void on_table_show_context(guint button, guint32 activate_time, const Glib::RefPtr<CanvasGroupDbTable>& table);
+  void on_table_moved(Glib::RefPtr<CanvasGroupDbTable> table);
+  void on_table_show_context(guint button, guint32 activate_time, Glib::RefPtr<CanvasGroupDbTable> table);
 
-  void on_context_menu_edit_fields(const Glib::RefPtr<CanvasGroupDbTable>& table);
-  void on_context_menu_edit_relationships(const Glib::RefPtr<CanvasGroupDbTable>& table);
+  void on_context_menu_edit_fields(Glib::RefPtr<CanvasGroupDbTable> table);
+  void on_context_menu_edit_relationships(Glib::RefPtr<CanvasGroupDbTable> table);
 
   void on_scroll_value_changed();
 
@@ -93,6 +93,9 @@ private:
   Glib::RefPtr<Goocanvas::Group> m_group_tables;
   Glib::RefPtr<Goocanvas::Group> m_group_lines;
 
+  typedef std::list<sigc::connection> type_list_connections;
+  type_list_connections m_list_table_connections;
+  
   //Context menu:
   Gtk::Menu* m_context_menu;
   Glib::RefPtr<Gtk::ActionGroup> m_context_menu_action_group;



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