Data folder / working folder question / bug?

Found the issue for my original post here Typical data folder packaging not working and pared it down to the minimum code to reproduce. This happened when I updated from 008 to 009. Can someone help me figure out what’s going on here?

When I use #1 to make the window and run system("pwd;") to see what folder OF is running out of, I get the correct folder: /Users/custom/Desktop/of_v0.9.4_osx_release/apps/myApps/tester-6/bin/tester-6.app/Contents/Resources.

But when I use #2, I get /Users/custom/Desktop/of_v0.9.4_osx_release/apps/myApps/tester-6/bin, which causes problems when trying to package things in the data folder.

Can anyone help me understand what’s going on?

main.cpp:

#include "ofMain.h"
#include "ofApp.h"

//========================================================================
int main( ){
    
    // #1. default way of starting app in 009, commenting out
//	ofSetupOpenGL(1024,768,OF_WINDOW);

    // #2. way I'd been doing it in 008, causes problems
    ofAppGlutWindow window;
    ofSetupOpenGL(&window, 1024,768, OF_WINDOW);
    


	ofRunApp(new ofApp());

}

sample ofApp.cpp:

#include "ofApp.h"

//--------------------------------------------------------------
void ofApp::setup(){
    system("pwd;");
}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){

}

Hmm thats strange.
What if you do in ofApp::setup?

cout << " OF data path is " << ofFilePath::getAbsolutePath( ofToDataPath("") ) << endl; 

In OF the default path for loading files will be the .app path + “/data/”
So I would expect your path to end:

..apps/myApps/tester-6/bin/data/

If you want to force your OF app to load files from Resources you can put this in the start of ofApp::setup():

ofSetDataPathRoot("../Resources/");

I usually use data/ external to the app for development and then bundle it when sharing the software.
This code will auto switch based on if it sees a data/ folder in the Resources app bundle.

bool isOFDataFolderBundled = false;
if( ofFile::doesFileExist("../Resources/data", false) ){
    isOFDataFolderBundled = true;
}
if( isOFDataFolderBundled ){
    ofSetDataPathRoot("../Resources/data/");
}

I hope that helps!
Theo

1 Like

Thanks for the tip, I’ve added your code into ofApp.cpp like this:

//--------------------------------------------------------------
void ofApp::setup(){
    cout << "Working directory: " << system("pwd;");
    cout << " OF data path is " << ofFilePath::getAbsolutePath( ofToDataPath("") ) << endl;
}

//--------------------------------------------------------------
void ofApp::update(){

}

//--------------------------------------------------------------
void ofApp::draw(){

}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    ofSetDataPathRoot("../Resources/");
    cout << " OF data path is NOW " << ofFilePath::getAbsolutePath( ofToDataPath("") ) << endl;
}

With the #1 009 version that works, this is the output:

Working directory: /Users/custom/Desktop/of_v0.9.4_osx_release/apps/myApps/tester-6/bin/tester-6.app/Contents/Resources
OF data path is /Users/custom/Desktop/of_v0.9.4_osx_release/apps/myApps/tester-6/bin/data/
OF data path is NOW /Users/custom/Desktop/of_v0.9.4_osx_release/apps/myApps/tester-6/bin/tester-6.app/Contents/Resources/

… is great. The data folder has been moved within the app and is packaged properly. But with the #2 008 non-working version, the output is this:

Working directory: /Users/custom/Desktop/of_v0.9.4_osx_release/apps/myApps/tester-6/bin
OF data path is /Users/custom/Desktop/of_v0.9.4_osx_release/apps/myApps/tester-6/bin/data/
OF data path is NOW /Users/custom/Desktop/of_v0.9.4_osx_release/apps/myApps/tester-6/bin/../Resources/

… which is the problem. That Resources folder neither exists nor is inside of the app. Still struggling to understand why it’s doing this.

Also, I don’t remember why I originally changed it from

ofSetupOpenGL(1024,768,OF_WINDOW);

to

ofAppGlutWindow window;
ofSetupOpenGL(&window, 1024,768, OF_WINDOW);

What is the difference between the two methods?

I think this could be a bug with ofAppGLUTWindow which is not really supported anymore.
There were cases of it switching CWD sometimes, I can’t remember why though.

In 008 do you see the issue if you do just?:

ofSetupOpenGL(1024,768, OF_WINDOW);
ofRunApp(new ofApp());

in main.cpp

And keep the same code in ofApp::setup?

Thanks!
Theo