View Full Version : Can't use openGL in MacOSX

09-06-2004, 05:52 PM
I am a new developer in Mac OS X.
I tried to compile some openGL programs with FLTK (www.fltk.org). I always get a "Bus error" when I try to run it. When I looked into it using gdb, it always occures where I initialize some array and pass that into openGL, say

GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 0.0, 0.3, 0.3, 0.0 };

GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };

> glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);

I get error in the line indicated. When I gdb that part of code, it seems that the array light_ambient is changed when the code is executed. I wonder if openGL in Mac blows up the stack
Any help? I am interested what kind of windowing toolkit you are using.

By the way, the above code compiles and works in linux.

09-07-2004, 08:21 AM
Well it should work on the face of things.

That is a static and if it's in scope (which it must be to compile) then it should work.

Are you sure you don't declare it again somewhere in the scope of your glLight call.

Also make sure that the array is big enough for the parameters (it seems to be with your example but I dunno if that's the exact code you're getting your crash on).

Hmm... just a thought but maybe that glLight call on the Mac remembers the pointer and tries to reference it out of scope but that makes no sense, the pointer would probably still work unless it's on the stack (i.e. unless you declare inside the function), but this would be a serious implementation bug on the Mac. That still doesn't explain gdb showing altered contents so I'm back to thinking you are declaring that pointer again somewhere.

09-09-2004, 01:28 AM
I use the Mac OpenGL everyday, and have code like that littered all over the place. It just works.

Some other things that might be wrong (shooting in the dark, bear with me):
* Is FLTK softlinking OpenGL, and has a wrong or NULL address for glLight?
* Try running the program under openGL profiler (Found in /Developer/Applications/Graphic Tools). Enable breakpointing on errors and see if anything pops up.
* Try the Mac-opengl mailing list. Lots of the apple devs hand out there.