From 9ccc56e162554c292b25408246e3680b8f14eea7 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 8 Dec 2018 21:18:54 +0100 Subject: [PATCH] Fix CheckOption crash on session-reload The ToggleAction has a lifetime of the UI, independent of the CheckOption widget. The CheckOption needs to unsubscribe from the signal_toggled() signal when it is deleted. Also a CheckOption without a Action makes no sense. require _action to be give at instantiation time. --- gtk2_ardour/option_editor.cc | 22 +++++++++++++--------- gtk2_ardour/option_editor.h | 8 +++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/gtk2_ardour/option_editor.cc b/gtk2_ardour/option_editor.cc index 875e611452..3482f66980 100644 --- a/gtk2_ardour/option_editor.cc +++ b/gtk2_ardour/option_editor.cc @@ -213,18 +213,22 @@ CheckOption::CheckOption (string const & i, string const & n, Glib::RefPtrsignal_toggled().connect (sigc::mem_fun (*this, &CheckOption::toggled)); Gtkmm2ext::Activatable::set_related_action (act); - if (_action) { + assert (_action); - action_sensitivity_changed (); + action_sensitivity_changed (); - Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (_action); - if (tact) { - action_toggled (); - tact->signal_toggled().connect (sigc::mem_fun (*this, &CheckOption::action_toggled)); - } - - _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &CheckOption::action_sensitivity_changed)); + Glib::RefPtr tact = Glib::RefPtr::cast_dynamic (_action); + if (tact) { + action_toggled (); + _callback_connection = tact->signal_toggled().connect (sigc::mem_fun (*this, &CheckOption::action_toggled)); } + + _action->connect_property_changed ("sensitive", sigc::mem_fun (*this, &CheckOption::action_sensitivity_changed)); +} + +CheckOption::~CheckOption () +{ + _callback_connection.disconnect (); } void diff --git a/gtk2_ardour/option_editor.h b/gtk2_ardour/option_editor.h index d6738889f3..749df8f90c 100644 --- a/gtk2_ardour/option_editor.h +++ b/gtk2_ardour/option_editor.h @@ -193,6 +193,7 @@ class CheckOption : public OptionEditorComponent , public Gtkmm2ext::Activatable { public: CheckOption (std::string const &, std::string const &, Glib::RefPtr act ); + virtual ~CheckOption (); void set_state_from_config () {} void parameter_changed (std::string const &) {} void add_to_page (OptionEditorPage*); @@ -203,17 +204,18 @@ public: Gtk::Widget& tip_widget() { return *_button; } +protected: void action_toggled (); void action_sensitivity_changed () {} void action_visibility_changed () {} -protected: virtual void toggled (); - sigc::slot _get; ///< slot to get the configuration variable's value - sigc::slot _set; ///< slot to set the configuration variable's value Gtk::CheckButton* _button; ///< UI button Gtk::Label* _label; ///< label for button, so we can use markup + +private: + sigc::connection _callback_connection; }; /** Component which provides the UI to handle a boolean option using a GTK CheckButton */ -- 2.30.2