File access / ofToDataPath

I noticed (and previously noticed discussion about) the difference in ofToDataPath in 007.

I’m generally getting negative results in windows, and positive results in osx iff the function is being called after or during setup().

Is it possible to enact some defaults for ofToDataPath() so even if the correct path has not been yet correctly found, we can always use a …/…/…/data for osx (or whatever it is) and respective default for windows.

and should we throw a fatal error if somebody calls this when openFrameworks isn’t ready yet?

i presume there’s a mail-thread on this already, perhaps any knowledge from there. All I can find so far is:

Explaining is the first part of solving :slight_smile:

I noticed the working path changes from testApp::testApp() to testApp::setup().
I’m using the constructor for testApp() with an initializer list because I need to
pass some arguments to member instances.

It would be good if ofToDataPath() takes this into account.

Best,
Diederick

ahh - can you file an issue?
thanks!


Theo Watson

I must have missed/deleted that mailing list conversation, might be nice to list here how one coudl encounter that error in case someone else runs into (assuming in doesn’t get fixed). I just tried starting a test from terminal and from Finder and both times ofToDataPath() didn’t change when called in main() before testApp(), in testApp(), and in testApp::setup(), so I’m curious.

In terms of a fix, my 2p is that a default configured path over error+exit is definitely preferable.

there’s a quick solution to this that i haven’t heard anyone mention before.

we change this:

  
  
void ofSetDataPathRoot(string newRoot){  
...  
	dataPathRoot = newRoot;  
}  
  
//--------------------------------------------------  
string ofToDataPath(string path, bool makeAbsolute){  
...  
}  
  

to this:

  
  
static bool isDataPathSet = false;  
void ofSetDataPathRoot(string newRoot){  
...  
	dataPathRoot = newRoot;  
	isDataPathSet = true;  
}  
  
//--------------------------------------------------  
string ofToDataPath(string path, bool makeAbsolute){  
	if(!isDataPathSet) {  
		ofSetDataPathRoot(dataPathRoot);  
	}  
...  
}  
  

then we remove ofSetDataPathRoot from wherever else it shows up in OF. kind of a lazy initialization pattern.

+1. that seems the obvious way to go

i’ve put this implementation into
https://github.com/elliotwoods/openFrameworks/tree/ofToDataPath
still need to check it works (in the middle of some other changes)
but that branch should be as kyle described

ok, works for me on osx.
pull request at https://github.com/openframeworks/openFrameworks/pull/734