openframeworks / openframeworks/openFrameworks

can't access Resources/ inside main()

Open
#6,148 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

close
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

I have an app that needs to do some things (like decide whether to decorate the window) before the app is run. This needs to be configured by a file inside the Resources/ folder. Usually the solution is to add ofSetDataPathRoot("../Resources"); but that doesn't work inside main():

#include "ofMain.h"
int main() {
    ofSetDataPathRoot("../Resources");
    ofLog() << ofToDataPath(".", true);
}
[notice ] /Users/kyle/Documents/openFrameworks/apps/Project/App/bin/../Resources/.

I also tried adding ofRestoreWorkingDirectoryToDefault(), ofSetDataPathRoot(".") and ofToDataPath(".") before ofSetDataPathRoot().

The only solution I found is to imitate the code inside defaultDataPath():

ofSetDataPathRoot(ofFilePath::join(ofFilePath::getCurrentExeDir(), "../Resources"));

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing ofSetDataPathRoot(), ofToDataPath(), and defaultDataPath(), then compare their behavior when called from main(). Inspect the existing ofFilePath::getCurrentExeDir() workaround and verify the expected Resources/ path on macOS; done means the documented call works inside main() without manually reproducing defaultDataPath().

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.