From 2c48aabe081d745f5128acb49bb41e1aa80a4c9b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 14 Jul 2023 19:03:32 +0200 Subject: [PATCH] Handle race condition when removing route before routeUI This fixes a crash when removing the monitor section. The monitor route goes away, but the GUI remains. The IOButton may still process previously queued cross-thread signals. In many cases this was not an issue since the route's memory was not immediately released or shared_ptr destruction only happened a short time later. --- gtk2_ardour/io_button.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gtk2_ardour/io_button.cc b/gtk2_ardour/io_button.cc index 023c9258ac..3f153d1683 100644 --- a/gtk2_ardour/io_button.cc +++ b/gtk2_ardour/io_button.cc @@ -483,6 +483,9 @@ IOButton::port_pretty_name_changed (std::string pn) void IOButton::port_connected_or_disconnected (std::weak_ptr wa, std::weak_ptr wb) { + if (!_route) { + return; + } std::shared_ptr a = wa.lock (); std::shared_ptr b = wb.lock (); @@ -702,6 +705,14 @@ IOButton::update () std::shared_ptr bundle; _bundle_connections.drop_connections (); + if (!_route) { + /* There may still be a signal queued before `set_route (0)` unsets the route + * and unsubscribes. invalidation only happens when the button is destroyed. */ + set_text (_input ? _("Input") : _("Output")); + set_tooltip (this, ""); + return; + } + set_label (*this, _route->session (), bundle, _input ? _route->input () : _route->output ()); if (bundle) {