xcode instruments screwing up paths
after a few hours i found out that why my app crashed when trying to use the xcode instruments (activity monitor, CPU sampler, leaks etc.):
apparently using the Instruments changes the working directory to my "Macintosh HD", so it doesn't find the needed resources that are in the same folder as my app ( i checked it running "system("pwd")").
for instance using fstream (c++)
fstream file;
file.open("myfile.txt", ios::in);
I assumed it would look for myfile.txt in the same directory of the app, and it does normally but not while using instruments
Any ideas how to fix this?
apparently using the Instruments changes the working directory to my "Macintosh HD", so it doesn't find the needed resources that are in the same folder as my app ( i checked it running "system("pwd")").
for instance using fstream (c++)
fstream file;
file.open("myfile.txt", ios::in);
I assumed it would look for myfile.txt in the same directory of the app, and it does normally but not while using instruments
Any ideas how to fix this?
©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Never assume your working directory at application startup will be the directory containing your application bundle; in most cases, it won't be. Use NSBundle or CFBundle to retrieve the path to your application (or more appropriately, its resources directory, since you shouldn't be storing files as siblings to it).
Thx, i'll have to get my hands in cocoa a bit then.
Though i still don't think it was such a weird thing to assume
Edit: for anyone interested, i found the problem in SDLMain.m i.e. if the app is not launched from the finder (gFinderLaunch=false) setupWorkingDirectory function is not called hence the problems.
Though i still don't think it was such a weird thing to assume

Edit: for anyone interested, i found the problem in SDLMain.m i.e. if the app is not launched from the finder (gFinderLaunch=false) setupWorkingDirectory function is not called hence the problems.
©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
here's some code that I believe OSC gave me a year ago or so:
-wyrmmage
Code:
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef resourcesURL = CFBundleCopyBundleURL(mainBundle);
char path[PATH_MAX];
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
fprintf(stderr, "Can't change to Resources direcory; something's seriously wrong\n");
exit(EXIT_FAILURE);
}
CFRelease(resourcesURL);
chdir(path);Worlds at War (Current Project) - http://www.awkward-games.com/forum/
SDLMain.m's Cocoa; you can do it much more easily:
But Najdorf already has that code or similar; the problem was it wasn't being called
http://blog.onesadcookie.com/2007/12/fin...files.html
Code:
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
[[NSFileManager defaultManager] changeCurrentDirectoryPath:resourcePath];But Najdorf already has that code or similar; the problem was it wasn't being called

http://blog.onesadcookie.com/2007/12/fin...files.html
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Viewing console output while running an app in Instruments | TomorrowPlusX | 1 | 3,166 |
Oct 5, 2011 04:51 AM Last Post: TomorrowPlusX |
|
| Xcode and library search paths | WhatMeWorry | 4 | 5,913 |
Dec 11, 2006 04:09 PM Last Post: WhatMeWorry |
|
| Fixing Include Paths | vbuser1338 | 4 | 2,824 |
May 28, 2006 05:15 PM Last Post: vbuser1338 |
|

