Can't run open GL in mac os X 10.3

I am a new developer in Mac OS X.
I tried to compile some openGL programs with FLTK ( 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 code I compiled was migrated from Linux, which worked fine.

The usual cause of this sort of thing is making OpenGL calls without having a current OpenGL context. This isn’t useful or recommended on any OS, but on Mac OS X it causes a crash – as it should :wink:

To check this, #include <OpenGL/OpenGL.h>, and printf("%p
", CGLGetCurrentContext()); just before you make the crashing call. If it prints out 0x0, that’s your problem. Delay your GL calls until you’ve made your window.

If that’s not it, you’re going to need to post some more code for us to help.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.