andyvn22
andyvn22

Reputation: 14824

Cocoa app gives EXC_BAD_ACCESS on any GL function

It seems that no matter what GL function I call, I get EXC_BAD_ACCESS. However, I'm calling these functions in readFromURL:ofType:error: of an NSDocument subclass, for some offscreen drawing. If I remove that code, and try to use GL later, once everything's loaded, everything works fine. Is this a GL context issue?

I read Apple's GL guide, but in the section about offscreen drawing, it just told me how to use framebuffers. Which I do, but since glGenFramebuffersEXT crashes just like everything else, it's not very helpful.

Is there some sort of context creation I need to perform, and if so, what's the best way to do it?

Upvotes: 1

Views: 502

Answers (1)

hamstergene
hamstergene

Reputation: 24429

Yes, OpenGL calls need a context. If you have NSOpenGLView, you need to get its context and make it current:

[[openGLView openGLContext] makeCurrentContext];
// glCalls()

If you're not using NSOpenGLView, you can create NSOpenGLContext youself.

Upvotes: 3

Related Questions