CodeWeed
CodeWeed

Reputation: 1071

EXC_BAD_ACCESS (code=2, address=0x20) even when NSZombieEnabled

I am getting a crash with EXC_BAD_ACCESS on my application, and I enabled the NSZombie on the executable scheme for debugging. I still get this crash even though the NSZombie enabled. The prime suspect is a thread (not the main thread) that causing this error. I am doing some kvo stuff in my code. it seems to come from it. I cannot find where it causes the problem. here is the backtrace for the thread. Can anyone tell me how to pin point the problem ? any clues or or debugging tips would be appreciated.

UPDATE : I tried to run the analyzer and the program just stopped and closed itself while running on the analyzer. No messages nothing... just closed silently and the recording stopped. I am not very good at looking at the analyzer, but can anyone tell me where to look at ?

* thread #9: tid = 0x2803, 0x00cfdb3e Foundation`__block_global_4 + 420, stop reason = EXC_BAD_ACCESS (code=2, address=0x20)
    frame #0: 0x00cfdb3e Foundation`__block_global_4 + 420
    frame #1: 0x00c5b9d7 Foundation`-[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 675
    frame #2: 0x00c5b72e Foundation`-[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:usingBlock:] + 63
    frame #3: 0x00cfd994 Foundation`____NSOQDelayedAttachPendingOperations_block_invoke_0 + 98
    frame #4: 0x00c5b9d7 Foundation`-[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 675
    frame #5: 0x00c5b72e Foundation`-[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:usingBlock:] + 63
    frame #6: 0x00c84e7b Foundation`__NSOQDelayedAttachPendingOperations + 156
    frame #7: 0x01615014 libdispatch.dylib`_dispatch_client_callout + 14
    frame #8: 0x01604fd6 libdispatch.dylib`_dispatch_after_timer_callback + 28
    frame #9: 0x01615014 libdispatch.dylib`_dispatch_client_callout + 14
    frame #10: 0x0160c8b7 libdispatch.dylib`_dispatch_source_latch_and_call + 219
    frame #11: 0x01608405 libdispatch.dylib`_dispatch_source_invoke + 322
    frame #12: 0x01606280 libdispatch.dylib`_dispatch_root_queue_drain + 231
    frame #13: 0x01606450 libdispatch.dylib`_dispatch_worker_thread2 + 39
    frame #14: 0x995eee12 libsystem_c.dylib`_pthread_wqthread + 441

Upvotes: 2

Views: 2236

Answers (1)

Wil Shipley
Wil Shipley

Reputation: 9553

It's really, really dangerous to use KVO across threads. In this case, it looks like you're modifying a value in thread #9, which is triggering the KVO message there. However, if your observer depends on being in the main thread (e.g., it does anything with the user interface, or it doesn't have protection around any data it accesses), your app will crash.

Have you stepped through the app one line at a time to see which line causes the crash?

Upvotes: 1

Related Questions