ofThread and ofxXmlSettings (weird error)

Hello everyone.

At the moment I have a weird error that i can’t understand.

The thingie is: I have a method in a class that create a thread like this

void loadDocument(){
        ActionThread* thread = new ActionThread(data, path);

then in ActionThread.h

class ActionThread : public ofThread{

bool toLoad;
Data* data;
string path;

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

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

void threadedFunction(){

and in Data.cpp

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

So, this is the idea of the code. The problem is when i do the method “loadDocument” twice, the second one will rise an error at “xmlDocument.load(path)”. The second path can be or not the same path as the first one. Doesn´t matter what path i select for the second one, it will rise always an error saying “std::out_of_range at memory location”. Without threads, i mean doing the loadDocument without any thread, it works, but i need them because some loads take a while.

Anyone here have an ideia why this happen? By the way, it crashes in ofUtils.cpp at

string ofToDataPath(string path, bool makeAbsolute) 

method when it checks

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

Thanks for your time.


[quote=“Wazhup, post:1, topic:16669”]
void Data::loadDocument(string path){
ofxXmlSettings xmlDocument;
xmlDocument.load(path); <------------

ofxXmlSettings should not be declared in there but in a more “global” scope,


class Data{
ofxXmlSettings xmlDocument;
void loadDocument(string path);

and then in your .cpp
void Data::loadDocument(string path){

Data is a horrible name for a class.
check if thread is running before calling it to start
and make sure you handle the case your user closes your app while you are still threading

this might help you:Archive.zip (3.1 KB)

Hello again Igiso :smiley:

Well, i figured out the error. Wasnt from load -.- Debugger said that was there, but wasn’t. You know, the beautiful world of threads make things like this :smiley:

ps: Data isnt the class name, i just did it as example.

Anyway thanks for your time again.

no worries, glad you figured it out