mirror of
https://github.com/brunoherbelin/vimix.git
synced 2025-12-11 18:34:58 +01:00
BugFix: interrupting recursive session loading
Prevent crash on recursive (infinite) loading of session file (containing itself).
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "SearchVisitor.h"
|
||||
|
||||
#include "Scene.h"
|
||||
#include "MediaSource.h"
|
||||
#include "Session.h"
|
||||
#include "SessionSource.h"
|
||||
|
||||
SearchVisitor::SearchVisitor(Node *node) : Visitor(), node_(node), found_(false)
|
||||
{
|
||||
@@ -42,12 +47,11 @@ void SearchVisitor::visit(Scene &n)
|
||||
|
||||
|
||||
|
||||
SearchFileVisitor::SearchFileVisitor(std::string filename) : Visitor(), filename_(filename), found_(false)
|
||||
SearchFileVisitor::SearchFileVisitor() : Visitor()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SearchFileVisitor::visit(Node &n)
|
||||
{
|
||||
|
||||
@@ -55,13 +59,8 @@ void SearchFileVisitor::visit(Node &n)
|
||||
|
||||
void SearchFileVisitor::visit(Group &n)
|
||||
{
|
||||
if (found_)
|
||||
return;
|
||||
|
||||
for (NodeSet::iterator node = n.begin(); node != n.end(); node++) {
|
||||
(*node)->accept(*this);
|
||||
if (found_)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,10 +80,29 @@ void SearchFileVisitor::visit(Scene &n)
|
||||
|
||||
void SearchFileVisitor::visit (MediaSource& s)
|
||||
{
|
||||
|
||||
filenames_.push_back( s.path() );
|
||||
}
|
||||
|
||||
void SearchFileVisitor::visit (SessionFileSource& s)
|
||||
{
|
||||
|
||||
filenames_.push_back( s.path() );
|
||||
}
|
||||
|
||||
std::list<std::string> SearchFileVisitor::parse (Session *se)
|
||||
{
|
||||
SearchFileVisitor sv;
|
||||
|
||||
for (auto iter = se->begin(); iter != se->end(); iter++){
|
||||
(*iter)->accept(sv);
|
||||
}
|
||||
|
||||
return sv.filenames();
|
||||
}
|
||||
|
||||
bool SearchFileVisitor::find (Session *se, std::string path)
|
||||
{
|
||||
std::list<std::string> filenames = parse (se);
|
||||
return std::find(filenames.begin(), filenames.end(), path) != filenames.end();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user