glMatrixMode() causes bus error

FoolyCooly

Registered
I'm really confused. I recently updated to xcode and now my opengl project will not run. I have a c++ class setup to "automate" a lot of the opengl while i play with the shapes etc. glObject square.drawSquare(); type stuff.

However, when executing my code, it compiles fine, i get a "<programName> has exited due to signal 10 (SIGBUS)." and then a generic "bus error" when compiling directly in the terminal. If I block off all the glcommands, like glMatrixMode(), then the program compiles and runs with test strings displaying appropriately, but if i leave even one glcommand open, the program compiles and I get the runtime bus error. When i follow through with the debugger it tells me there is a badexec or something while the debugger sits on some mac assembly. I'm afraid to touch the assembly as the debugger is inside a gl framework header/source file.

The project is a revamp of a cocoa++ file that I am converting to strict c++ using core gl, so calls to create a window or grab the screen or set up gl aren't implemented in the program. But the only glcommands i'm using are the ones to declare and create objects like glColor3f or glBegin()/glEnd() but not to actually display anything and as I've said, the program runs fine without the glcommands inserted.

The program in cocoa, however, runs as always and displays the correct shapes etc. I'm really lost, as I have changed very little in my code, save for the cocoa class and function names and #import to #include, which, compiles fine without gripe. I am not trying to display shapes yet, just get the program to print out "drawing a square" in place of a graphic.

Thanks for any help, FLCL
 
There are a number of gl commands in the library that will crash your program if you do not have a context created and selected. I ran into that problem a couple times (querying extensions). I haven't used Cocoa in a while, last time I did though - and with OpenGL - I used Interface Builder which I think took care of the context creation. All I did was add the draw code.

What exactly are you using to create your window and attaching a gl rendering context to it? Are you using Carbon + AGL? Have you tried GLUT?
 
That was the problem. When testing the cocoa version, i would only declare the object and not call a draw function. When testing the c++ version, i would declare the object and call a draw function. When I tested the draw function without a context in the cocoa version - i got a similar error. I thought that it would cause problems and was pretty sure that was it, but I had forgotten that I was calling a draw function in my main.cp and not in my main.mm. Thanks for the clarity.

I am using coregl to grab the fullscreen and setup the context etc. its supposed to be the more direct way and resembles agl in use quite a bit, plus you don't have to use cocoa to use it. I like cocoa, but don't want to have to debug my cocoa and my opengl at the same time.

Again, thanks for your help, FLCL
 
Try GLUT. It even has routines to create a window, and even multiple GL views, for you. Plus it also provides keyboard (and I think mouse) message handling.
 
Back
Top