[glom/glom-1-28] Notebook_Data: Destructor: Work around crash during shutdown.



commit 5bcb39ce4edc6214adff4da57da825b0f84669f4
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Jan 14 11:46:13 2015 +0100

    Notebook_Data: Destructor: Work around crash during shutdown.
    
    * glom/utility_widgets/notebook_noframe.[h|cc]:
      Add a hacky remove_all_pages_without_signalling() method
      to avoid us calling get_parent() while this widget is being
      removed, because that is causing get_parent() to be called on
      a GtkWidget that is no longer valid. This has started happening
      recently so I suspect a change in GTK+ or gtkmm.
      I have not put in the time to identify what is really going
      wrong.
    * glom/mode_data/notebook_data.cc: Destructor: Call the new
      workaround method.

 glom/mode_data/notebook_data.cc          |    4 ++++
 glom/utility_widgets/notebook_noframe.cc |   18 ++++++++++++++++--
 glom/utility_widgets/notebook_noframe.h  |    6 ++++++
 3 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/glom/mode_data/notebook_data.cc b/glom/mode_data/notebook_data.cc
index 2a16fed..d2d0a22 100644
--- a/glom/mode_data/notebook_data.cc
+++ b/glom/mode_data/notebook_data.cc
@@ -84,6 +84,10 @@ Notebook_Data::Notebook_Data()
 
 Notebook_Data::~Notebook_Data()
 {
+  //This is a workaround to prevent our Glom::Frame_Glom::on_notebook_data_switch_page
+  //mDestructorStarted = true;
+  remove_all_pages_without_signalling();
+
   remove_view(&m_Box_List);
   remove_view(&m_Box_Details);
 }
diff --git a/glom/utility_widgets/notebook_noframe.cc b/glom/utility_widgets/notebook_noframe.cc
index 0694401..8fba0d6 100644
--- a/glom/utility_widgets/notebook_noframe.cc
+++ b/glom/utility_widgets/notebook_noframe.cc
@@ -44,8 +44,9 @@ NotebookNoFrame::NotebookNoFrame()
 
   //Let the StackSwitcher switch the Stack:
   m_box_tabs.set_stack(m_box_pages);
-  m_box_pages.property_visible_child().signal_changed().connect(
-    sigc::mem_fun(*this, &NotebookNoFrame::on_visible_child_changed));
+  m_connection_visible_child_changed =
+    m_box_pages.property_visible_child().signal_changed().connect(
+      sigc::mem_fun(*this, &NotebookNoFrame::on_visible_child_changed));
 
   //m_box_tabs.set_spacing(UiUtils::DEFAULT_SPACING_SMALL);
 
@@ -84,6 +85,19 @@ void NotebookNoFrame::append_page(Widget& child, const Glib::ustring& name, cons
   m_box_pages.add(child, name, tab_label);
 }
 
+void NotebookNoFrame::remove_all_pages_without_signalling() {
+  //Prevent Glom::NotebookNoFrame::on_visible_child_changed() from being called,
+  //which then tries to call get_parent() on, for instance, the parent
+  //Frame_Glom container widget, for which GTK_IS_WIDGET can fail if the
+  //Notebook_NoFrame is being removed during Frame_Glom destruction.
+  //This shouldn't be necessary and wasn't necessary with earlier GTK+ or gtkmm
+  //versions.
+  m_connection_visible_child_changed.disconnect();
+
+  UiUtils::container_remove_all(m_box_pages);
+}
+
+
 std::vector<Gtk::Widget*> NotebookNoFrame::get_page_children()
 {
   return m_box_pages.get_children();
diff --git a/glom/utility_widgets/notebook_noframe.h b/glom/utility_widgets/notebook_noframe.h
index 74bce7a..bdba999 100644
--- a/glom/utility_widgets/notebook_noframe.h
+++ b/glom/utility_widgets/notebook_noframe.h
@@ -41,6 +41,11 @@ public:
 
   void append_page(Widget& child, const Glib::ustring& name, const Glib::ustring& tab_label);
 
+  /** This allows a workaround for GTK_IS_WIDGET(parent) failing sometimes
+   * during destruction. See the comment in the code.
+   */
+  void remove_all_pages_without_signalling();
+
   Gtk::Widget* get_visible_child();
   Glib::ustring get_visible_child_name() const;
   void set_visible_child(const Glib::ustring& name);
@@ -62,6 +67,7 @@ private:
   Gtk::Box m_box_action_left, m_box_action_right;
 
   type_signal_switch_page m_signal_switch_page;
+  sigc::connection m_connection_visible_child_changed;
 };
 
 } //namespace Glom


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