My app crashes sometimes at this point:
NSMutableData* position = [NSMutableData dataWithLength: 3 * sizeof(CGPoint)];
when NSMutableData calls the autorelease.
Here’s the crash log:
Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x00000001, 0xe7ffdefe Crashed Thread: 0 Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 CoreFoundation 0x343dea60 _CFAutoreleasePoolAddObject + 136 1 CoreFoundation 0x343de9cc -[NSObject(NSObject) autorelease] + 8 2 Foundation 0x30c49166 +[NSMutableData(NSMutableData) dataWithLength:] + 34
Do you have any idea why?
UPDATE:
The variable “position” is returned and used this way:
NSMutableData *positionData = [[SFinder sharedFinder] move:self.crId] ;
CGPoint *path = [positionData mutableBytes];
CGPoint location0 = path[0];
CGPoint location1 = path[1];
CGPoint location = path[2];
UPDATE 2:
I removed the code with NSMutableData, but the app keeps crashing randomly. On the debug console there is a message:
*** attempt to pop an unknown autorelease pool (0x5830000)
stack:
Thread 0 Crashed: Dispatch queue: com.apple.main-thread 0 CoreFoundation 0x01348b69 _CFAutoreleasePoolPop + 201 1 UIKit 0x008a947c _wrapRunLoopWithAutoreleasePoolHandler + 68 2 CoreFoundation 0x013edfbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27 3 CoreFoundation 0x013830e7 __CFRunLoopDoObservers + 295 4 CoreFoundation 0x0134bbd7 __CFRunLoopRun + 1575 5 CoreFoundation 0x0134b240 CFRunLoopRunSpecific + 208 6 CoreFoundation 0x0134b161 CFRunLoopRunInMode + 97 7 GraphicsServices 0x029b3268 GSEventRunModal + 217 8 GraphicsServices 0x029b332d GSEventRun + 115 9 UIKit 0x008a942e UIApplicationMain + 1160 10 MyApp 0x000029f4 main + 100 (main.m:13) 11 MyApp 0x00002985 start + 53
Found the problem. There is an issue with
NSMutableData. It occures when you init it withinitWithLength, ordataWithLengthand try to insert data troughmutableBytes. When you insert the last byte it makes some allocation somewhere else (even if that part of the memory is owned by an other object) causingEXC_BAD_ACCESSand other memory related errors. So initiating it with length+1 bytes solved the problem.