Openframework, ofThread and ofxXmlSettings (strange error)

At the moment I have a strange error that I cannot figure out.

Thing: I have a method in a class that creates a thread like this

    void loadDocument(){
            ActionThread* thread = new ActionThread(data, path);
            thread->start();
    }

      

then in ActionThread.h

    class ActionThread : public ofThread{

    public:
    bool toLoad;
    Data* data;
    string path;

    ActionThread(Data* data, string path){
            this->toLoad = true;
            this->data = data;
            this->path = path;
    }

    void start(){
            startThread(true, false);
    }

    void threadedFunction(){
            if(toLoad)
                    data->loadDocument(path);
            stopThread();
    }
    }

      

and in Data.cpp

    void Data::loadDocument(string path){
            ofxXmlSettings xmlDocument;
            xmlDocument.load(path); <------------   
    }

      

So this is the idea behind the code. The problem is that I call the method twice loadDocument

, the second one on error xmlDocument.load(path)

. The second path may or may not be the same as the first. It doesn't matter which path I take for the second, there will always be an error saying std::out_of_range at memory location

. Without threads I mean to do loadDocument

without any thread, it works, but I need them because some loads take a while.

Does anyone have an idea why this is happening? By the way, it crashes in inUtils.cpp at

    string ofToDataPath(string path, bool makeAbsolute) 

      

when he checks

    if (defaultWorkingDirectory().toString() != getWorkingDir().toString())

      

+3


source to share





All Articles