Reputation: 6513
When I'm trying to compile this program
#include <stdlib.h>
#include <GLUT/glut.h>
int main(int argc, char* argv[]) {
glGetError();
exit(1);
}
with
cc -std=c99 main.c -framework OpenGL -framework GLUT -framework Cocoa
on Mac OSX Sierra 10.12.1 with LLVM version 8.0.0 (clang-800.0.42.1), I get a segmentation fault:
* thread #1: tid = 0xc0a7d, 0x00007fffd7ecea07 libGL.dylib`glGetError + 13, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
frame #0: 0x00007fffd7ecea07 libGL.dylib`glGetError + 13
I'm completely lost as to what is going on here. I can only assume it is some sort of linking issue. I don't have access to a pre-Sierra machine, but I had not encountered this issue before, so I assume something must have changed in Sierra.
Upvotes: 0
Views: 941
Reputation: 90521
You have not created an OpenGL context nor made it current. glGetError()
is looking up the thread's current context and indexing into an internal function table to call the "real" implementation appropriate for that context. The lookup gets a null context address, so the access of the function table gets an access violation.
Upvotes: 2