diff --git a/src/proc/asset/db.hpp b/src/proc/asset/db.hpp index 78352680a..6e8914ec9 100644 --- a/src/proc/asset/db.hpp +++ b/src/proc/asset/db.hpp @@ -103,8 +103,15 @@ namespace asset return dynamic_pointer_cast (find (hash)); } - /** removes all registered assets and invokes - * Asset::unlink() on each to break cyclic dependencies + /** removes all registered assets and does something similar + * to Asset::unlink() on each to break cyclic dependencies + * (we can't use the real unlink()-function, because this + * will propagate, including calls to the AssetManager. + * As the destructor of DB needs to call clear(), this + * could result in segfaults. This doesn't seem to be + * a problem, though, because we register and process + * \i all assets and the net effect is just breaking + * any cyclic dependencies) */ void clear () throw() @@ -113,8 +120,8 @@ namespace asset { IdHashtable::const_iterator i = table.begin(); IdHashtable::const_iterator e = table.end(); - for ( ; i!=e ; ++i ) - i->second->unlink(); + for ( ; i!=e ; ++i ) + i->second->dependants.clear(); table.clear(); } diff --git a/tests/51asset.tests b/tests/51asset.tests index 06882dbca..6f8afceee 100644 --- a/tests/51asset.tests +++ b/tests/51asset.tests @@ -24,7 +24,8 @@ PLANNED "DeleteAsset_test" DeleteAsset_test <getParents())); ASSERT (contains (a3->getParents(), a2)); // but up-links remain intact + a2_->call_unlink(a1->getID()); a2_->set_depend(a1); PAsset a4 = TA::create(a1); ASSERT (a1 == a2->getParents()[0]); diff --git a/tests/components/proc/asset/testasset.cpp b/tests/components/proc/asset/testasset.cpp new file mode 100644 index 000000000..e8420c203 --- /dev/null +++ b/tests/components/proc/asset/testasset.cpp @@ -0,0 +1,123 @@ +/* + TestClip - test clip (stub) for checking EDL/Session functionality + + Copyright (C) CinelerraCV + 2007, Christian Thaeter + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +* *****************************************************/ + + +#include "proc/asset/testasset.hpp" +#include "proc/assetmanager.hpp" + +using std::tr1::static_pointer_cast; + +namespace asset + { + namespace test + { + + namespace + { + uint counter (0); + + /** @internal helper generating continuosely + * different new asset identities + */ + Asset::Ident + make_new_ident () + { + return Asset::Ident ( str(format("TestAsset.%i") % counter) + , Category (META) + , "test" + , counter++ + ); + } + Asset::Ident + make_new_ident (PAsset& ref) + { + return Asset::Ident ( str(format("%s-TestAsset.%i") % ref->ident.name + % counter) + , ref->ident.category + , "test" + , counter++ + ); + } + } + + + template + TestAsset::TestAsset () + : A(make_new_ident ()) + { }; + + + template + TestAsset::TestAsset (PAsset& pRef) + : A(make_new_ident (pRef)) + { + this->defineDependency(pRef); + }; + + + /** @internal helper for the create()-Functions + * retrieving the smart ptr created automatically + * within AssetManager by the Asset base class ctor + */ + template + shared_ptr > + TestAsset::ptrFromThis () + { + return static_pointer_cast,Asset> + (AssetManager::instance().getAsset (this->id)); + }; + + + + } // namespace test + +} // namespace asset + + + + + /*********************************************************/ + /* explicit template instantiations for some Asset Kinds */ + /*********************************************************/ + +#include "proc/asset/unknown.hpp" + + +namespace asset + { + namespace test + { + + template TestAsset::TestAsset (); + template TestAsset::TestAsset (); + + template TestAsset::TestAsset (PAsset& pRef); + template TestAsset::TestAsset (PAsset& pRef); + + template shared_ptr > TestAsset::ptrFromThis (); + template shared_ptr > TestAsset::ptrFromThis (); + + + + } // namespace test + +} // namespace asset diff --git a/tests/components/proc/asset/testasset.hpp b/tests/components/proc/asset/testasset.hpp index b40ac3a77..551a7d8d9 100644 --- a/tests/components/proc/asset/testasset.hpp +++ b/tests/components/proc/asset/testasset.hpp @@ -41,35 +41,6 @@ namespace asset namespace test { - namespace - { - uint counter (0); - - /** @internal helper generating continuosely - * different new asset identities - */ - Asset::Ident - make_ident () - { - return Asset::Ident ( str(format("TestAsset.%i") % counter) - , Category (META) - , "test" - , counter++ - ); - } - Asset::Ident - make_ident (PAsset& ref) - { - return Asset::Ident ( str(format("%s-TestAsset.%i") % ref->ident.name - % counter) - , ref->ident.category - , "test" - , counter++ - ); - } - } - - /** * Test(mock) asset subclass usable for hijacking a given @@ -81,22 +52,24 @@ namespace asset template class TestAsset : public A { - TestAsset () : A(make_ident ()) { }; - TestAsset (PAsset& pRef) : A(make_ident (pRef)) { this->defineDependency(pRef); }; + TestAsset () ; + TestAsset (PAsset&); ///< declared dependant on the given Asset static void deleter (TestAsset* aa) { delete aa; } public: typedef shared_ptr > PA; - static PA create () { return PA (new TestAsset, &deleter); } - static PA create (PAsset& pRef) { return PA (new TestAsset (pRef), &deleter); } + static PA create () { return (new TestAsset )->ptrFromThis(); } + static PA create (PAsset& pRef) { return (new TestAsset (pRef))->ptrFromThis(); } /* === interesting asset features we want to access for tests === */ void call_unlink () { this->unlink (); } void call_unlink (IDA target) { this->unlink (target); } void set_depend (PAsset parent) { this->defineDependency (parent); } + private: + PA ptrFromThis (); };