views:

311

answers:

1

I am currently working directly with Cocoa for the first time to built a screen saver. Now I came across a problem when trying to load resources from within the .saver bundle. I basically have a small C++ wrapper class to load .exr files using freeImage. This works as long as I use absoulte paths, but that's not very useful, is it? So, basically, I tried everything: putting the .exr file at the level of the .saver bundle itself, inside the bundles Resources folder, and so on.

Then I simply tried to load the .exr like this, but without success:

particleTex = [self loadExrTexture:@"ball.exr"];

I also tried making it go to the .saver bundles location like this:

particleTex = [self loadExrTexture:@"../../../ball.exr"];

...to maybe load the .exr from that location, but without success.

I then came across this:

NSString * path = [[NSBundle mainBundle] pathForResource:@"ball" ofType:@"exr"];
const char * pChar = [path UTF8String];

...which seems to be a common way to find resources in Cocoa, but for some reason it's empty in my case. Any ideas about that? I really tried out anything that came to my mind without success so I would be glad about some input!

+2  A: 

You should use NSBundle bundleWithIdentifier: instead of mainBundle to get a reference to your screen saver bundle.

From the discussion section:

This method is typically used by frameworks and plug-ins to locate their own bundle at runtime. This method may be somewhat more efficient than trying to locate the bundle using the bundleForClass: method.

0xced
Thanks that is exactly what I was looking for!
moka