DispatchTimer icon indicating copy to clipboard operation
DispatchTimer copied to clipboard

EXC_BAD_INSTRUCTON (code=EXC_1386_INVOP, subcode=0x0) When Spamming Pause/Unpause

Open AnthonyUccello opened this issue 9 years ago • 5 comments

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.

AnthonyUccello avatar Mar 08 '16 00:03 AnthonyUccello

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?

ambientlight avatar Mar 08 '16 01:03 ambientlight

Everything is on the main queue (via dispatch_get_main_queue())

AnthonyUccello avatar Mar 08 '16 01:03 AnthonyUccello

I have some more info on the crash. Here is a print out of a full log. Nothing is nil going into the _setupTimerSource.

dispatchtimer

AnthonyUccello avatar Mar 12 '16 00:03 AnthonyUccello

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

AnthonyUccello avatar Mar 12 '16 00:03 AnthonyUccello

Thank you for the feedback. Working on it...

ambientlight avatar Mar 13 '16 20:03 ambientlight