I am debugging an EXC_BAD_ACCESS in Objective-C++ and like a good SO student I have set an Environment variable of NSZombieEnabled to YES.
I’m not getting any Zombies, though, just (gdb) in the log and then EXC_BAD_ACCESS on various (C++) lines of my code.
Question: Am I using Zombies wrong, or do they just ignore the C++ parts of my project?
Example:
if (this->squares[i][j] == 1) // <-- EXC_BAD_ACCESS on this line. The array exists and shows up in the debugger... and i and j both exist and are 0.
Stack:
Thread 1, Queue : com.apple.main-thread
#0 0x00009309 in Board::draw(float, float, float, float, float) at /Developer/of_007_iphone/apps/cwi007/iTicTacToe/src/gameplay/gameBoard.cpp:53
#1 0x0000a2f1 in SuperBoard::drawBig(float, float, float) ()
#2 0x000044b8 in testApp::draw() ()
#3 0x0020fc16 in ofAppiPhoneWindow::timerLoop() ()
#4 0x00218db9 in -[ofxiPhoneAppDelegate timerLoop] ()
#5 0x00ab1749 in __NSFireTimer ()
#6 0x01f898c3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ ()
#7 0x01f8ae74 in __CFRunLoopDoTimer ()
#8 0x01ee72c9 in __CFRunLoopRun ()
#9 0x01ee6840 in CFRunLoopRunSpecific ()
#10 0x01ee6761 in CFRunLoopRunInMode ()
#11 0x027651c4 in GSEventRunModal ()
#12 0x02765289 in GSEventRun ()
#13 0x00d29c93 in UIApplicationMain ()
#14 0x002106e1 in ofAppiPhoneWindow::runAppViaInfiniteLoop(ofBaseApp*) ()
#15 0x002219ae in ofRunApp(ofBaseApp*) ()
#16 0x00002fd6 in main ()
Zombies are very helpful because they will flag in the debugger when you send a message to an object that has been deallocated. They only work with Objective-C code however.
EXC_BAD_ACCESSerrors are tricky in that at the point they occur, that line of code might have nothing to do with the root cause of the error. It may offer a clue.That’s because the Objective-C runtime will only deallocated released objects when all the objects that reside in a particular chunk of memory have been released and are eligible for deallocation.
See here for a great explanation and instructions on how to track down these pesky errors:
Lou Franco’s Understanding EXC_BAD_ACCESS