That's an easy one. -Easy for me, because I had much trouble with it earlier. =)

Remember to retain your timer:

- (void)timerStop
{
        if(timer)
        {
                [timer invalidate];
                [timer release];
                timer = NULL;
        }
}

- (void)timerStart:(double)aSecondInterval
{
        [self timerStop];
timer = [[NSTimer scheduledTimerWithTimeInterval:aSecondInterval target:self selector:@selector(_updateDisplay:) userInfo:NULL repeats:YES] retain];
}

...and make timer a member variable of your class.

You probably experience your crash, because the timer is autoreleased. If you retain it, it'll live. However, you'll have to remember the timer object, so you can stop it later, so add NSTimer *timer; as a member variable of your class...

- (void)dealloc
{
        [self timerStop];
        [super dealloc];
}


Love,
Jens

On Dec 14, 2008, at 06:07, Daniel Luis dos Santos wrote:

Hello,

I have a NSTimer that is created every time I press a button. It then calls the update function successively until some amount of time passes. When I press the button again I get a EXC_BAD_ACCESS on the timer's initialization :

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: step target: self
                selector: @selector(_updateDisplay:) userInfo: nil repeats: 
YES];

step is a double, and _updateDisplay has the right signature.
The stack trace is something like :

#0      0x90705558 in tiny_malloc_from_free_list
#1      0x906fe3ed in szone_malloc
#2      0x906fe2f8 in malloc_zone_malloc
#3      0x932b9451 in _CFRuntimeCreateInstance
#4      0x9327f844 in CFDateCreate
#5 0x93329f63 in -[__NSPlaceholderDate initWithTimeIntervalSinceReferenceDate:]
#6      0x9332a7fd in +[NSDate dateWithTimeIntervalSinceNow:]
#7 0x9034aa3f in +[NSTimer(NSTimer) scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:]

I haven't any idea,...

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jensbauer%40christian.net

This email sent to jensba...@christian.net


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to