DispatchTimer
DispatchTimer copied to clipboard
EXC_BAD_INSTRUCTON (code=EXC_1386_INVOP, subcode=0x0) When Spamming Pause/Unpause
Thank you for this awesome pauseable timer.
One (hard to reproduce) bug I am encountering is this:
EXC_BAD_INSTRUCTON (code=EXC_1386_INVOP, subcode=0x0)
It occurs randomly (rarely) when I spam pausing/unpausing a DispatchTimer.
The line that crashes is here:
_setupTimerSource(self.interval, startOffset: self.interval - UInt(_elapsedAccumulatedTime), leeway: 0)
Inside of
public func resume()
{
if (self.status == .Paused)
{
//NSLog("%ld milliseconds left till fire", self.interval - UInt(_elapsedAccumulatedTime))
_timerSource = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue)
_setupTimerSource(self.interval, startOffset: self.interval - UInt(_elapsedAccumulatedTime), leeway: 0)
dispatch_resume(_timerSource)
_lastActiveDateº = NSDate()
self.status = .Active
}
}
I think it has something to do with invalid params being passed but all of my variables were valid (I was using 1000 millisecond timer).
Any thoughts?
My project basically has a timer with a 1 second interval that counts down a value which the user can pause with a pause button. So spamming pause/unpause will rarely cause this crash.
Haven't yet encountered this issue. Will need a bit of time to access. You are pausing/resuming the timer from the same dispatch_queue you instantiated the timer with, right?
Everything is on the main queue (via dispatch_get_main_queue())
I have some more info on the crash. Here is a print out of a full log. Nothing is nil going into the _setupTimerSource.

I think this stack post might have some insight.
http://stackoverflow.com/questions/24337791/exc-bad-instruction-code-exc-i386-invop-subcode-0x0-on-dispatch-semaphore-dis
Thank you for the feedback. Working on it...