0

I've got the following code which stops at if (time != currentTime) and launches the debugger. I cannot find any info about it, and trying to log an exception isn't working.

- (void)viewWillAppear:(BOOL)animated {
    [self startIt];
}

- (void)viewWillDisappear:(BOOL)animated {
    [self stopIt];
}

- (void)startIt {
    isRunning = YES;
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
        @try {
            NSTimeInterval time = currentTime;
            while (isRunning) {
                if (time != currentTime) {  // app stops here with EXC_??? (11)
                    time = currentTime;
                    // do other work
                }
            }
        }
        @catch (NSException *e) {
            NSLog(@"Exception %@", e);
        }
    });
}

// Delegate method called when broadcasting time
- (void)updateCurrentTime:(NSInteger)time {
    @synchronized(self) {
        currentTime = time;
    }
    [anotherView doStuffWIthTime:time];
}

- (void)stopIt {
    isRunning = NO;
}

Viewing the stack trace isn't helping me much:

* thread #6: tid = 0x2503, 0x0021e6e3 Project`__46-[MyViewControlleriPad startRunQueue]_block_invoke() + 131 at MyViewControlleriPad.m:343, stop reason = EXC_??? (11) (code=0, subcode=0x0)
    frame #0: 0x0021e6e3 Project`__46-[MyViewControlleriPad startRunQueue]_block_invoke() + 131 at MyViewControlleriPad.m:343
    frame #1: 0x03f1653f libdispatch.dylib`_dispatch_call_block_and_release + 15
    frame #2: 0x03f28014 libdispatch.dylib`_dispatch_client_callout + 14
    frame #3: 0x03f192e8 libdispatch.dylib`_dispatch_root_queue_drain + 335
    frame #4: 0x03f19450 libdispatch.dylib`_dispatch_worker_thread2 + 39
    frame #5: 0x96f33e72 libsystem_c.dylib`_pthread_wqthread + 441

EDIT: Updated to show isRunning being set. I'm now realizing I'm not synchronizing access to it. Will that fix this issue? I was thinking it was with currentTime.

ravun
  • 1,523
  • 9
  • 27
  • 45

0 Answers0