I am having a strange problem accessing files via SDL2 on Mac. I am using Xcode 4 in OS X Mountain Lion and I am using SDL2 as the frame. I am NOT compiling SDL2 from the source. I added the framework to the set, as well as the files that I need to download. The program builds and works fine with Xcode, but the files do not load outside the editor (I.E., if I double-click the standalone .app file, the files do not load). This is what my .app package looks like:
MyApp.app/ Contents/ Frameworks/ SDL2.framework/ MacOS/ MyApp Resources/ Configure.txt MyBMP.bmp Info.plist PkgInfo
In my C code, I tried to do this:
SDL_LoadBMP("MyApp.app/Contents/Resources/MyBMP.bmp");
Just like this:
SDL_LoadBMP("MyBMP.bmp");
And almost everything in between. I also tried to access the text file via:
FILE* data = fopen("MyApp.app/Contents/Resources/Configure.txt", "r");
and
FILE* data = fopen("Configure.txt", "r");
not successful. Only long absolute paths work in the Xcode editor, while nothing I tried worked in standalone .app.
Do you have other problems? I downloaded files when I used SDL 1.2, but for some reason SDL2 doesnβt load anything. Does SDL2 do something weird with the active directory during initialization?
------------- EDIT 1 -------------- My last attempt to find out what is happening with this code:
#include "SDL2/SDL.h" #include "stdio.h" #include "stdlib.h" int main (int argc, char** argv){ if(SDL_Init(SDL_INIT_EVERYTHING) < 0) return EXIT_FAILURE; FILE* test = fopen("Test.txt", "w"); if (!test) return EXIT_FAILURE; fprintf(test, "Let see where this ends up..."); fclose(test); return EXIT_SUCCESS;
When launched from the Xcode 4 editor, this works as expected. In the Debug folder, next to my .app file, there is a Test.txt file containing the phrase "Let me see where it ends ...". However, when you start by clicking on the stand-alone application, the program immediately ends and the text file is not found. I checked the logs and it just says that the program exited with code 1. Thanks to a more thorough analysis, it seems that fopen()
is failing. Does anyone have an idea of ββwhat might be happening?