Re: NSTimer firing issue
Re: NSTimer firing issue
- Subject: Re: NSTimer firing issue
- From: Julian Pellico <email@hidden>
- Date: Fri, 23 Jul 2004 00:41:22 -0700
Hi guys,
Well no one stepped forward on this one yet :-P
I've figured out a partial answer - this code is getting run on a
different thread than I was hoping. In fact, it gets called from a
thread that's exiting and is posting NSThreadWillExitNotifications.
The stack looks like:
0 - [solverView playForward]
1 - [AppController doPlayForward]
2 - [AppController solveDidEnd:returnCode:contextInfo:]
3 - [AppController solveALgorithmCompleted:]
4 - _nsNotificationCenterCallBack
......CFStorageDeleteValues, _CFNotificationCenter..........,
__NSFinalizeThreadData
So this thread doesn't even have a run loop. So now that I have an
idea of what's going on, does anyone have a suggestion for how to get
this code to run on my main thread?
On Thu, 22 Jul 2004 00:30:05 -0700, Julian Pellico <email@hidden> wrote:
>
Hi group,
>
>
First I'd just like to say that this has been a great list for a
>
budding Cocoa developer. I've always found the answers to be right on
>
:-D
>
>
Now, I'm doing some animation in my app and I want it to be controlled
>
by playback buttons. I keep an NSTimer* in a custom view that
>
receives commands from my app controller. At a certain point in the
>
app, I want playback to start occurring automatically, so I invoke the
>
playForward method below from my app controller. However, the timer
>
does not successfully fire at that point. I have to press my play
>
backward button in my app, or pause and then forward again in order
>
for the timer to fire.
>
>
The following code is in a custom view. The mode is initially PlaybackPause.
>
>
- (void) pause
>
{
>
if (mode == PlaybackPause)
>
return;
>
>
mode = PlaybackPause;
>
// Invalidate the timer
>
[animationTimer invalidate];
>
[animationTimer release];
>
animationTimer = nil;
>
>
}
>
>
- (void) playBackward
>
{
>
if (mode == PlaybackReverse)
>
return;
>
>
mode = PlaybackReverse;
>
// invalidate the timer
>
[animationTimer invalidate];
>
// release the current timer
>
[animationTimer release];
>
// create a new timer
>
animationTimer = [NSTimer scheduledTimerWithTimeInterval: ANIMATION_INTERVAL
>
target: self
>
selector:
>
@selector(solverViewAdvanceFrame)
>
userInfo: nil
>
repeats: YES];
>
[animationTimer retain];
>
}
>
>
- (void) playForward
>
{
>
if (mode == PlaybackForward)
>
return;
>
>
mode = PlaybackForward;
>
// invalidate the timer
>
[animationTimer invalidate];
>
// release the current timer
>
[animationTimer release];
>
// create a new timer
>
animationTimer = [NSTimer scheduledTimerWithTimeInterval: ANIMATION_INTERVAL
>
target: self
>
selector:
>
@selector(solverViewAdvanceFrame)
>
userInfo: nil
>
repeats: YES];
>
[animationTimer retain];
>
}
>
>
// Frame advancement
>
- (void) solverViewAdvanceFrame
>
{
>
NSLog(@"ANIMATE");
>
}
>
>
///////// END CODE SNIPPET
>
>
The debugger shows that animationTimer is 0x0 on that first run
>
through playForward, as expected. However, solverViewAdvanceFrame
>
isn't getting called. I don't get why the timer isn't firing at all
>
initially.
>
>
Feel free to ask for more code if that would help, or more info.
>
Thanks,
>
Julian
_______________________________________________
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.