OpenGL and Mac OS X (Carbon\Xcode) crashing

Started by
7 comments, last by playerWANG 19 years, 10 months ago
I''m a veteran DirectX\Win32 programmer but very much a n00b with Macs and OpenGL, period. But recently I dove into this strange new world and compiled a rotating texture mapped cube demo. It runs fine when I Build\Run but when I run it by itself (click on the executable outside the compiler) it crashes. Can anybody explain what I''m not doing?
Advertisement
Realized I didn''t give any specifics. I''m loading a TGA file externally, meaning it''s not encoded into the program. And I''m using the NeHe Lesson 6, MacOS version that I''ve converted for Carbon.
Sounds like your working directory is different whether you start it from the IDE or by hand.
You could try to use an absolute path to load the texture to test this.

Regards,
Jan

EDIT: I should think before writing

[edited by - jeickmann on June 11, 2004 2:23:18 PM]
If your tga is included in the bundle then there is a cocoa function getPathforResource in the NSBundle class that would give u the correct path for the resource.

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/ObjC_classic/Classes/NSBundle.html#//apple_ref/occ/cl/NSBundle
Can Cocoa and Carbon mix?
Unfortunately the FAQ at idevgames.com which would answer this is down, but you could try createmacgames.org for a more exhaustive answer...

The simplest response is that you need to use either the Carbon or the Cocoa API calls to set the current working directory to the parent of the app (or the "Resources" folder of the .app bundle)

Running from Project Builder/XCode, the current working directory is automatically set to the "build" directory of the project.

The default working directory is "/"; I''ve no idea why...

This is from memory, but it should perfrom the directory switch under Carbon (a lot longer than the Cocoa variant, which is two lines...):

CFURLRef resourceURL = CFBundleCopyResourcesDirectoryURL( CFBundleGetMainBundleURL());
char resourcePath[ 4096 ];
CFURLGetFileSystemRepresentation( resourceURL, TRUE, resourcePath, 4096 );
chdir( resourcePath );
CFRelease( resourceURL );
I have noticed this myself when using xcode. Directories can get screwed up on the project sometimes. When I create a project on my desktop, then later move it to a source folder in another directory, it won''t run, and sometimes won''t even compile. If you know how, try compiling it from the terminal manually, that usually works. Otherwise try fiddling with settings in xcode to make the build different, that can effect the problem you are having.

--------------------------------------------------------
Life would be so much easier if we could just get the source code.
--------------------------------------------------------Life would be so much easier if we could just get the source code.
Thanks a lot guys! Always assumed the working directory would the same as the folder the executable is in (like Windows is). I''ll try to work from that angle...

Does anybody have a good recommendation for a book for MacOS? Carbon, specificially? All I have found is ''Carbon Programming'', which is kind of vanilla and too choppy for my reading.
Hi, I have coded on the Mac quite a bit. The path issue is simple use this format "../dir/dir/filename" You have to remember you are using a Unix file system. Windows hides this I think from you. Also if you are moving from windows to OSX you will have to byte swap all your data that is not char(byte) so int, short, ect... all need to be byte swapped. So .tga files will need to have the width, height short swapped. Just to let you know heads up..

This topic is closed to new replies.

Advertisement