NSTimer in a secondary thread?
NSTimer in a secondary thread?
- Subject: NSTimer in a secondary thread?
- From: Pierre-Olivier Latour <email@hidden>
- Date: Wed, 21 Aug 2002 22:33:42 +0200
Hi,
I'm encapsulating my 3D engine inside a Cocoa interface. I'd like to do
rendering in a separate thread. However, I don't find the documentation very
clear on how to run an NSTimer inside another thread.
I'm trying the following code, but it does not work (the app crash about one
second after startup):
*****
- (void) catch:(NSTimer*)timer
{
NSLog(@"CATCH!");
}
- (void) test:(id)sender
{
NSAutoreleasePool* pool;
NSRunLoop* runLoop;
NSTimer* timer;
//Create an autorelease pool
pool = [[NSAutoreleasePool alloc] init];
//Add timer
runLoop = [NSRunLoop currentRunLoop];
timer = [NSTimer timerWithTimeInterval:1.0 target:self
selector:@selector(catch:) userInfo:NULL repeats:YES];
[runLoop addTimer:[timer retain] forMode:[runLoop currentMode]];
//Clear autorelease pool
[pool release];
NSLog(@"Exit!");
}
[NSThread detachNewThreadSelector:@selector(test:) toTarget:self
withObject:nil];
*****
Neither NSLog are called apparently.
What's the best method for my objective by the way? Should I use a NSTimer
or use low-level functions like "runMode:beforeDate:"? Or even do this:
while(1) {
[openGLView lockFocus];
render_frame();
[openGLView unlockFocus];
}
This solution seems to works fine, but I can't limit the framerate...
_____________________________________________________________
Pierre-Olivier Latour email@hidden
Lausanne, Switzerland
http://www.pol-online.net
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.