# SDL Error Code

This topic is 4073 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I copied the local "How to make tetris in an hour" SDL version, stuck it into Xcode, and built it. The following error message showed up after building:
GameInit > File not Found: blocks.bmp
OnInit > Game Init failed!
I found the code that was causing the problem:
	surfBlocks = SDL_LoadBMP("blocks.bmp");

if(!surfBlocks) {
return false;
}
I stuck the "blocks.bmp" file into my project and tried it again. No beans. So where does "SDL_LoadBMP()" look when finding bitmaps? From one website, it says it's under ~.app/Contents/Resources/ , and when I looked there, the file was right there!

##### Share on other sites
If there's no path, it should look in the same directory as your exe, unless it changes its current working directory behind the scenes.

##### Share on other sites
Quote:
 Original post by RepliconIf there's no path, it should look in the same directory as your exe, unless it changes its current working directory behind the scenes.

What do I do if there is a path/ can I create a path?

##### Share on other sites
It will look in the directory enclosing your .app by default. That is, if your app is in /Users/pie/Code/Foobar/build, then that's where it will look for your data.

If you give it a relative path ("data/foobar.png"), it will look in the path relative to your .app.

You can modify the SDLmain.m file to make it look inside the application bundle (so the data directory comes along with your application), but I generally only do this for release builds.

##### Share on other sites
Quote:
 Original post by RavuyaIt will look in the directory enclosing your .app by default. That is, if your app is in /Users/pie/Code/Foobar/build, then that's where it will look for your data.If you give it a relative path ("data/foobar.png"), it will look in the path relative to your .app.You can modify the SDLmain.m file to make it look inside the application bundle (so the data directory comes along with your application), but I generally only do this for release builds.

Thanks for the help. How would I make it look inside the application? And how do I get it to find the file in debug mode?

##### Share on other sites
in the directory the .xcode is during build xcode will create another folder called "build". in this folder it will create:

debug
or release
or default

folder. in this folder your app will appear after successfull building it. if it's the debug,release or default folder is effected by your current target, selected in xcode. you can set your current build configuration in project/set build configuration.

your working directory seems to be set in this function:

- (void) setupWorkingDirectory:(BOOL)shouldChdir{    if (shouldChdir)    {        char parentdir[MAXPATHLEN];		CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());		CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);		if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {	        assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */		}		CFRelease(url);		CFRelease(url2);	}}

don't know if you got the same SDLmain.m. but maybe just use the search engine to get more info about "CFBundleCopyBundleURL".

EDIT: in the end you just need to change parentdir. parentdir should be created with CFURLGetFileSystemRepresentation. if you commend the url2 line out and use url in CFURLGetFileSystemRepresentation your working directory should be set in the app. just try it out.

otherwise just place all resources beside the .app!

[Edited by - Eitsch on May 28, 2007 3:38:50 AM]

##### Share on other sites
Quote:
 Original post by Eitschin the directory the .xcode is during build xcode will create another folder called "build". in this folder it will create:debugor releaseor defaultfolder. in this folder your app will appear after successfull building it. if it's the debug,release or default folder is effected by your current target, selected in xcode. you can set your current build configuration in project/set build configuration.your working directory seems to be set in this function:- (void) setupWorkingDirectory:(BOOL)shouldChdir{ if (shouldChdir) { char parentdir[MAXPATHLEN]; CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url); if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) { assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */ } CFRelease(url); CFRelease(url2); }}don't know if you got the same SDLmain.m. but maybe just use the search engine to get more info about "CFBundleCopyBundleURL". otherwise just place all resources beside the .app!

Ok I didn't understand most of that... but I managed to figure it out from what I could understand...

##### Share on other sites
In order to copy the file into your .app when it is built, you must add it to a Copy Files build step.

Open your target, go down to Build Steps, and there should be a build step for Copy Files. I think the SDL Xcode template produces one Copy Files step for Resources and another one to copy the frameworks into Frameworks. Since your file is already inside the Resources directory in the bundle, it doesn't look like you have to do this step.

You'll probably need to change the code that Eitsch provided to chdir into the Resources folder of the bundle rather than the root directory of the bundle. That's easy; just change his code to copy the resources URL of the bundle instead of the bundle URL, like so:
- (void) setupWorkingDirectory:(BOOL)shouldChdir{    if (shouldChdir)    {        char parentdir[MAXPATHLEN];	CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); /* get the resources component instead of the main bundle URL */	if (CFURLGetFileSystemRepresentation(url, true, (UInt8 *)parentdir, MAXPATHLEN)) { /* convert to a path */	       assert ( chdir (parentdir) == 0 );   /* chdir to the Resources component of the bundle */	}	CFRelease(url);	CFRelease(url2);    }}
IIRC, this should work. I'm away from my Mac so I can't confirm if this compiles properly, but I've used something similar in the past. Check out the CFBundle reference documentation for more fun stuff you can do with app bundles.

Also, don't forget that shouldChdir won't be true in this code when you run it from Xcode! You'll have to modify the call to setupWorkingDirectory (in the same file) to pass YES instead of its normal argument.

##### Share on other sites
Ok, now this just isn't making any sense. I got it to work, and thanks to both of you for the effort...

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
17
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002297
×