iPhone Gameloop render update from a separate thread

Posted by Rich on Stack Overflow See other posts from Stack Overflow or by Rich
Published on 2009-03-06T19:12:03Z Indexed on 2010/04/18 0:23 UTC
Read the original article Hit count: 988

Filed under:
|
|

Hi,

I'm new to iPhone development. I have a game loop setup as follows.

(void)CreateGameTick:(NSTimeInterval) in_time
{
  [NSThread detachNewThreadSelector:@selector(GameTick) toTarget:self withObject:nil];
}

My basic game tick/render looks like this

(void)GameTick
{
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  CGRect wrect = [self bounds];

  while( m_running )
  {
    [self drawRect: wrect];
  }

  [pool release];       
}

My render function gets called. However nothing gets drawn (I am using Core Graphics to draw some lines on a derived UIView).

If I call my update via a timer then all is well and good.

Can you tell me why the render fails when done via threads? And is it possible to make it work via threads?

Thanks Rich

© Stack Overflow or respective owner

Related posts about iphone

Related posts about gameloop