From c0e135993c2e130f0adb6842b62077e68c6ad52b Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Sat, 10 Oct 2020 15:16:47 +0200 Subject: [PATCH] BugFix: prevent visitors for failed sources. Avoid duplicate list of source ids. --- DeviceSource.cpp | 3 ++- PatternSource.cpp | 3 ++- Session.cpp | 3 +++ SessionCreator.cpp | 40 ++++++++++++++++------------------------ SessionSource.cpp | 6 ++++-- Source.cpp | 3 ++- StreamSource.cpp | 3 ++- 7 files changed, 31 insertions(+), 30 deletions(-) diff --git a/DeviceSource.cpp b/DeviceSource.cpp index 2b14f0a..b129d89 100644 --- a/DeviceSource.cpp +++ b/DeviceSource.cpp @@ -393,7 +393,8 @@ void DeviceSource::setDevice(const std::string &devicename) void DeviceSource::accept(Visitor& v) { Source::accept(v); - v.visit(*this); + if (!failed()) + v.visit(*this); } bool DeviceSource::failed() const diff --git a/PatternSource.cpp b/PatternSource.cpp index d18ed48..f444a44 100644 --- a/PatternSource.cpp +++ b/PatternSource.cpp @@ -147,7 +147,8 @@ void PatternSource::setPattern(int type, glm::ivec2 resolution) void PatternSource::accept(Visitor& v) { Source::accept(v); - v.visit(*this); + if (!failed()) + v.visit(*this); } Pattern *PatternSource::pattern() const diff --git a/Session.cpp b/Session.cpp index cd1c674..f0cc184 100644 --- a/Session.cpp +++ b/Session.cpp @@ -257,6 +257,9 @@ std::list Session::getIdList() const for( auto sit = sources_.begin(); sit != sources_.end(); sit++) idlist.push_back( (*sit)->id() ); + // make sure no duplicate + idlist.unique(); + return idlist; } diff --git a/SessionCreator.cpp b/SessionCreator.cpp index 9f43064..0622746 100644 --- a/SessionCreator.cpp +++ b/SessionCreator.cpp @@ -104,6 +104,8 @@ SessionLoader::SessionLoader(Session *session): Visitor(), session_(session) void SessionLoader::load(XMLElement *sessionNode) { + sources_id_.clear(); + if (sessionNode != nullptr && session_ != nullptr) { XMLElement* sourceNode = sessionNode->FirstChildElement("Source"); @@ -147,7 +149,6 @@ void SessionLoader::load(XMLElement *sessionNode) // add source to session session_->addSource(load_source); - id__ = load_source->id(); } // get reference to the existing source else @@ -156,7 +157,7 @@ void SessionLoader::load(XMLElement *sessionNode) // apply config to source load_source->accept(*this); // remember - sources_id_.push_back( id__ ); + sources_id_.push_back( load_source->id() ); } // create clones after all sources, to be able to clone a source created above @@ -167,47 +168,38 @@ void SessionLoader::load(XMLElement *sessionNode) // verify type of node const char *pType = xmlCurrent_->Attribute("type"); - if (!pType) - continue; - if ( std::string(pType) == "CloneSource") { - - // clone to load - Source *clone_source = nullptr; + if ( pType && std::string(pType) == "CloneSource") { // check if a source with same id exists - uint64_t id__ = -1; + uint64_t id__ = 0; xmlCurrent_->QueryUnsigned64Attribute("id", &id__); SourceList::iterator sit = session_->find(id__); // no source clone with this id exists if ( sit == session_->end() ) { + // clone from given origin XMLElement* originNode = xmlCurrent_->FirstChildElement("origin"); if (originNode) { std::string sourcename = std::string ( originNode->GetText() ); SourceList::iterator origin = session_->find(sourcename); + // found the orign source if (origin != session_->end()) { // create a new source of type Clone - clone_source = (*origin)->clone(); + Source *clone_source = (*origin)->clone(); + // add source to session + session_->addSource(clone_source); + // apply config to source + clone_source->accept(*this); + // remember + sources_id_.push_back( clone_source->id() ); } } - // skip failed - if (!clone_source) - continue; - - // add source to session - session_->addSource(clone_source); - id__ = clone_source->id(); } - else - clone_source = *sit; - - // apply config to source - clone_source->accept(*this); - // remember - sources_id_.push_back( id__ ); } } + // make sure no duplicate + sources_id_.unique(); } } diff --git a/SessionSource.cpp b/SessionSource.cpp index 0f2502a..2a59f55 100644 --- a/SessionSource.cpp +++ b/SessionSource.cpp @@ -237,7 +237,8 @@ void SessionSource::render() void SessionSource::accept(Visitor& v) { Source::accept(v); - v.visit(*this); + if (!failed()) + v.visit(*this); } @@ -317,5 +318,6 @@ void RenderSource::render() void RenderSource::accept(Visitor& v) { Source::accept(v); - v.visit(*this); + if (!failed()) + v.visit(*this); } diff --git a/Source.cpp b/Source.cpp index 4f4a527..a84a01b 100644 --- a/Source.cpp +++ b/Source.cpp @@ -508,6 +508,7 @@ void CloneSource::render() void CloneSource::accept(Visitor& v) { Source::accept(v); - v.visit(*this); + if (!failed()) + v.visit(*this); } diff --git a/StreamSource.cpp b/StreamSource.cpp index 39aa051..25bd06d 100644 --- a/StreamSource.cpp +++ b/StreamSource.cpp @@ -33,7 +33,8 @@ void GenericStreamSource::setDescription(const std::string &desc) void GenericStreamSource::accept(Visitor& v) { Source::accept(v); - v.visit(*this); + if (!failed()) + v.visit(*this); } StreamSource::StreamSource() : Source()