From eb10d32d8b59f2158ba64ba55e310ba0f5f24170 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 14 May 2008 23:31:15 +0000 Subject: Fix clear patch command (ticket #18). Potential destruction race/leak fixes. More thorough thread assertions on graph object methods. git-svn-id: http://svn.drobilla.net/lad/ingen@1207 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/Store.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'src/libs/client/Store.cpp') diff --git a/src/libs/client/Store.cpp b/src/libs/client/Store.cpp index 24a30064..60c03049 100644 --- a/src/libs/client/Store.cpp +++ b/src/libs/client/Store.cpp @@ -60,7 +60,6 @@ Store::clear() { _objects.clear(); _plugins.clear(); - } @@ -352,8 +351,8 @@ Store::destruction_event(const Path& path) removed.reset(); - //cerr << "Store removed object " << path - // << ", count: " << removed.use_count(); + /*cerr << "Store removed object " << path + << ", count: " << removed.use_count();*/ } void @@ -482,11 +481,28 @@ Store::patch_polyphony_event(const Path& path, uint32_t poly) void Store::patch_cleared_event(const Path& path) { - SharedPtr patch = PtrCast(object(path)); - if (patch) - for (ObjectModel::const_iterator i = patch->children_begin(); i != patch->children_end(); ++i) - if (i->second->graph_parent() == patch.get()) - destruction_event(i->second->path()); + Objects::iterator i = _objects.find(path); + if (i != _objects.end()) { + assert((*i).second->path() == path); + SharedPtr patch = PtrCast(i->second); + + Objects::iterator first_descendant = i; + ++first_descendant; + Objects::iterator descendants_end = _objects.find_descendants_end(i); + SharedPtr< Table > > removed + = _objects.yank(first_descendant, descendants_end); + + for (Objects::iterator i = removed->begin(); i != removed->end(); ++i) { + SharedPtr model = PtrCast(i->second); + assert(model); + model->signal_destroyed.emit(); + if (model->parent() == patch) + patch->remove_child(model); + } + + } else { + cerr << "[Store] Unable to find patch " << path << " to clear." << endl; + } } @@ -498,7 +514,6 @@ Store::variable_change_event(const Path& subject_path, const string& predicate, if (!value) { cerr << "ERROR: variable '" << predicate << "' has no type" << endl; } else if (subject) { - cerr << "Set variable '" << predicate << "' with type " << (int)value.type() << endl; subject->set_variable(predicate, value); } else { add_variable_orphan(subject_path, predicate, value); -- cgit v1.2.1