xcode instruments screwing up paths

Member
Posts: 749
Joined: 2003.01
Post: #1
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?

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
Moderator
Posts: 1,552
Joined: 2003.10
Post: #2
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).
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #3
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 Rasp

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
Quote this message in a reply
Moderator
Posts: 370
Joined: 2006.08
Post: #4
here's some code that I believe OSC gave me a year ago or so:
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);
-wyrmmage

Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Quote this message in a reply
Luminary
Posts: 5,125
Joined: 2002.04
Post: #5
SDLMain.m's Cocoa; you can do it much more easily:

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 Rasp

http://blog.onesadcookie.com/2007/12/fin...files.html
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Viewing console output while running an app in Instruments TomorrowPlusX 1 3,163 Oct 5, 2011 04:51 AM
Last Post: TomorrowPlusX
  Xcode and library search paths WhatMeWorry 4 5,907 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