Multithreaded OpenGL

Posts: 49
Joined: 2002.05
Post: #1
I'm working on my CEGL editor which has an NSOpenGLView that needs to be constantly updated (redrawn). To do this I thought it would be best to control the updates in a separate thread. In addition to this the separate thread also updates my engine data. This is a Cocoa editor btw. The class that spawns the new thread is called EDIT_Controller. EDIT_Controller has an IB outlet for the NSOpenGLView. My new thread runs the message update:(id)anObject which is in EDIT_Controller.

Now on to the problem...
The new thread calls gameEngine->render(). The render method in my game engine makes many OpenGL calls. Whenever the program gets to one of these OpenGL calls it quits and I get this error:

CEGL_Editor has exited due to signal 10 (SIGBUS).

The update method looks like this:

- (void)update:(id)anObject
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    if(gameEngine) {
        [openGLView display];
    [pool release];

What I *think* the problem is, is that the new thread that has the OpenGL calls doesn't have the same memory accessibility as the main thread has ( if that makes any sense Smile ) and somehow this is causing the crashes.

Any ideas?

-- Ian
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
Yeah -- don't use multiple threads, use a timer. Your life will be much, much easier.

If you insist on pursuing the path of folly, you're going to need to make the OpenGL context current from your drawing thread, and make sure that both threads can't draw to the context simultaneously.

You should also be aware that very little of Cocoa is thread-safe. If your secondary thread needs to communicate with the main thread, it'll virtually have to use notifications to do it.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Multithreaded OpenGL Engine Technote OneSadCookie 8 4,763 Nov 13, 2006 01:27 PM
Last Post: OneSadCookie