From d1dd3e26772fabf3ed9ce5cb1372281756af13a4 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 20 Oct 2010 04:42:22 +0200 Subject: [PATCH] saveguard against deregistering from an alredy destroyed session --- src/lib/element-tracker.hpp | 7 +++++++ .../mobject/session/session-interface-modules.hpp | 9 +++++++++ .../session/session-element-tracker-test.cpp | 13 +++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/lib/element-tracker.hpp b/src/lib/element-tracker.hpp index dac3e3368..2a0515d08 100644 --- a/src/lib/element-tracker.hpp +++ b/src/lib/element-tracker.hpp @@ -181,6 +181,7 @@ namespace lib { void detach() { + if (!getRegistry) return; TAR& element = static_cast (*this); getRegistry().remove(element); @@ -222,6 +223,12 @@ namespace lib { establishRegistryLink (accessInstance); } + static void + deactivateRegistryLink() + { + getRegistry = RegistryLink(); // empty accessor function + } + protected: static RegistryLink getRegistry; }; diff --git a/src/proc/mobject/session/session-interface-modules.hpp b/src/proc/mobject/session/session-interface-modules.hpp index 3651ee3b8..46878a272 100644 --- a/src/proc/mobject/session/session-interface-modules.hpp +++ b/src/proc/mobject/session/session-interface-modules.hpp @@ -101,6 +101,7 @@ namespace session { SequenceTracker sequenceRegistry_; SessionInterfaceModules(); + ~SessionInterfaceModules(); }; @@ -116,6 +117,14 @@ namespace session { asset::Sequence::setRegistryInstance (sequenceRegistry_); } + inline + SessionInterfaceModules::~SessionInterfaceModules() + { + asset::Sequence::deactivateRegistryLink(); + asset::Timeline::deactivateRegistryLink(); + } + + }} // namespace mobject::session #endif diff --git a/tests/components/proc/mobject/session/session-element-tracker-test.cpp b/tests/components/proc/mobject/session/session-element-tracker-test.cpp index 10a333b1e..7b3cbca15 100644 --- a/tests/components/proc/mobject/session/session-element-tracker-test.cpp +++ b/tests/components/proc/mobject/session/session-element-tracker-test.cpp @@ -200,6 +200,19 @@ namespace test { CHECK (num_timelines + 1 == sess->timelines.size()); CHECK (anotherTimeline == sess->timelines[num_timelines]); // moved to the previous slot CHECK (specialTimeline.use_count() == 1); // we're holding the last reference + + verify_cleanup (anotherTimeline); + } + + + /** @test ensure the asset cleanup doesn't interfere with session shutdown + */ + void + verify_cleanup (PTimeline aTimeline_in_session) + { + REQUIRE (1 < aTimeline_in_session.use_count(), "test object should still be attached to session"); + Session::current.reset(); + aTimeline_in_session->detach(); // should be a no-op and not cause any invalid access } };