Fix missing calls to SessionHandlePtr::session_going_away()

This commit is contained in:
Robin Gareus 2024-11-06 03:41:17 +01:00
parent 9eb1bf81f7
commit fd658ffcbb
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 21 additions and 1 deletions

View File

@ -52,6 +52,8 @@ class LIBARDOUR_API SessionHandlePtr
PBD::ScopedConnectionList _session_connections;
virtual void session_going_away ();
private:
bool _gone_away_emitted;
};
} /* namespace */

View File

@ -31,6 +31,7 @@ using namespace PBD;
SessionHandlePtr::SessionHandlePtr (Session* s)
: _session (s)
, _gone_away_emitted (false)
{
if (_session) {
_session->DropReferences.connect_same_thread (_session_connections, std::bind (&SessionHandlePtr::session_going_away, this));
@ -42,6 +43,19 @@ SessionHandlePtr::set_session (Session* s)
{
_session_connections.drop_connections ();
/* DropReferences may already have been disconnected due to signal emission ordering.
*
* An instance of this class (e.g. Ardour_UI) will need to call ::set_session on member instances.
*
* Yet, when session_going_away() first calls set_session (0) on an instance that has SessionHandlePtr members,
* they will reach here, and disocnnect signal handlers. Their derived implementation of ::session_going_away()
* will not be called.
*/
if (!_gone_away_emitted && _session && !s) {
_gone_away_emitted = true;
session_going_away ();
}
if (_session) {
_session = 0;
}
@ -49,14 +63,18 @@ SessionHandlePtr::set_session (Session* s)
if (s) {
_session = s;
_session->DropReferences.connect_same_thread (_session_connections, std::bind (&SessionHandlePtr::session_going_away, this));
_gone_away_emitted = false;
}
}
void
SessionHandlePtr::session_going_away ()
{
if (_session && !_gone_away_emitted) {
_gone_away_emitted = true;
set_session (0);
}
}
/*-------------------------*/