Crashing with ASIHTTPRequest and NSOperationQueue when cancelling operations - iphone

I'm having a really hard time when trying to cancel requests in an NSOperationQueue.
Before deallocating my 'engine' object, I call a cancelOperations method to cancel everything in the queue, so this will include in flight ASIHTTPRequests and queued ones... e.g.
Engine.m
-(void)getContent {
if (![self queue]) {
[self setQueue:[[[NSOperationQueue alloc] init] autorelease]];
}
NSURL *url = [NSURL URLWithString:#"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request setDidFinishSelector:#selector(requestDone:)];
[[self queue] addOperation:request]; //queue is an NSOperationQueue
}
-(void)requestDone:(ASIHTTPRequest)*request {
// Do something with request
}
-(void)cancelOperations {
[self.queue cancelAllOperations];
[self.queue waitUntilAllOperationsAreFinished];
}
-(void)dealloc {
[super dealloc];
}
Now, In my engine I have a number of getContent type methods, so my queue has different request objects in it. The flow when using an Engine object is:
1) Open View Controller - view did load - alloc and init Engine object
2) // Call various getContent style methods to queue up some operations
3) Upon view exit, call [engine cancelOperations]; in order to (a) Stop any network requests in flight, and to also empty the queue
4) Deallocate the view, and with that the engine: [engine release];
This works fine if all requests have finished in the queue (as it's empty), however if I cancelOperations whilst a request is active, the application crashes with a EXC_BAD_ACCESS error... but AFTER the engine is deallocated successfully...
Any ideas why this would be?
--EDIT--
Adding Backtrace for error:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000000b0000000
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
objc_msgSend() selector name: respondsToSelector:
iPhone Simulator 225, iPhone OS 4.1 (iPhone 4/8B117)
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x02cb5907 objc_msgSend + 27
1 CoreFoundation 0x02ac95cd __invoking___ + 29
2 CoreFoundation 0x02ac94a1 -[NSInvocation invoke] + 145
3 Foundation 0x0015a3ca __NSThreadPerformPerform + 251
4 CoreFoundation 0x02b39faf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
5 CoreFoundation 0x02a9839b __CFRunLoopDoSources0 + 571
6 CoreFoundation 0x02a97896 __CFRunLoopRun + 470
7 CoreFoundation 0x02a97350 CFRunLoopRunSpecific + 208
8 CoreFoundation 0x02a97271 CFRunLoopRunInMode + 97
9 GraphicsServices 0x0320c00c GSEventRunModal + 217
10 GraphicsServices 0x0320c0d1 GSEventRun + 115
11 UIKit 0x003e9af2 UIApplicationMain + 1160
12 Clicky 0x000027d4 main + 102 (main.m:14)
13 Clicky 0x00002765 start + 53
Thread 1: Dispatch queue: com.apple.libdispatch-manager
0 libSystem.B.dylib 0x97cfe942 kevent + 10
1 libSystem.B.dylib 0x97cff05c _dispatch_mgr_invoke + 215
2 libSystem.B.dylib 0x97cfe519 _dispatch_queue_invoke + 163
3 libSystem.B.dylib 0x97cfe2be _dispatch_worker_thread2 + 240
4 libSystem.B.dylib 0x97cfdd41 _pthread_wqthread + 390
5 libSystem.B.dylib 0x97cfdb86 start_wqthread + 30
Thread 2:
0 libSystem.B.dylib 0x97cfd9d2 __workq_kernreturn + 10
1 libSystem.B.dylib 0x97cfdf68 _pthread_wqthread + 941
2 libSystem.B.dylib 0x97cfdb86 start_wqthread + 30
Thread 3: WebThread
0 libSystem.B.dylib 0x97cd80fa mach_msg_trap + 10
1 libSystem.B.dylib 0x97cd8867 mach_msg + 68
2 CoreFoundation 0x02b3a436 __CFRunLoopServiceMachPort + 150
3 CoreFoundation 0x02a97984 __CFRunLoopRun + 708
4 CoreFoundation 0x02a97350 CFRunLoopRunSpecific + 208
5 CoreFoundation 0x02a97271 CFRunLoopRunInMode + 97
6 WebCore 0x034093a3 RunWebThread(void*) + 483
7 libSystem.B.dylib 0x97d0581d _pthread_start + 345
8 libSystem.B.dylib 0x97d056a2 thread_start + 34
Thread 4:
0 libSystem.B.dylib 0x97cfd9d2 __workq_kernreturn + 10
1 libSystem.B.dylib 0x97cfdf68 _pthread_wqthread + 941
2 libSystem.B.dylib 0x97cfdb86 start_wqthread + 30
Thread 5:
0 libSystem.B.dylib 0x97cd80fa mach_msg_trap + 10
1 libSystem.B.dylib 0x97cd8867 mach_msg + 68
2 CoreFoundation 0x02b3a436 __CFRunLoopServiceMachPort + 150
3 CoreFoundation 0x02a97984 __CFRunLoopRun + 708
4 CoreFoundation 0x02a97350 CFRunLoopRunSpecific + 208
5 CoreFoundation 0x02a9a614 CFRunLoopRun + 84
6 Clicky 0x0001fdb7 +[ASIHTTPRequest runRequests] + 167 (ASIHTTPRequest.m:4093)
7 Foundation 0x0014576c -[NSThread main] + 81
8 Foundation 0x001456f8 __NSThread__main__ + 1387
9 libSystem.B.dylib 0x97d0581d _pthread_start + 345
10 libSystem.B.dylib 0x97d056a2 thread_start + 34
Thread 6:
0 libSystem.B.dylib 0x97cd80fa mach_msg_trap + 10
1 libSystem.B.dylib 0x97cd8867 mach_msg + 68
2 CoreFoundation 0x02b3a436 __CFRunLoopServiceMachPort + 150
3 CoreFoundation 0x02a97984 __CFRunLoopRun + 708
4 CoreFoundation 0x02a97350 CFRunLoopRunSpecific + 208
5 CoreFoundation 0x02a97271 CFRunLoopRunInMode + 97
6 Foundation 0x0017ab86 +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 398
7 Foundation 0x0014576c -[NSThread main] + 81
8 Foundation 0x001456f8 __NSThread__main__ + 1387
9 libSystem.B.dylib 0x97d0581d _pthread_start + 345
10 libSystem.B.dylib 0x97d056a2 thread_start + 34
Thread 7:
0 libSystem.B.dylib 0x97cf7086 select$DARWIN_EXTSN + 10
1 CoreFoundation 0x02acbb5e __CFSocketManager + 798
2 libSystem.B.dylib 0x97d0581d _pthread_start + 345
3 libSystem.B.dylib 0x97d056a2 thread_start + 34
Thread 8:
0 libSystem.B.dylib 0x97cfd9d2 __workq_kernreturn + 10
1 libSystem.B.dylib 0x97cfdf68 _pthread_wqthread + 941
2 libSystem.B.dylib 0x97cfdb86 start_wqthread + 30
Thread 0 crashed with X86 Thread State (32-bit):
eax: 0x06641500 ebx: 0x000143f3 ecx: 0x0008e1c8 edx: 0x06606075
edi: 0xb0000000 esi: 0x066554c4 ebp: 0xbfffdef8 esp: 0xbfffdec4
ss: 0x0000001f efl: 0x00010206 eip: 0x02cb5907 cs: 0x00000017
ds: 0x0000001f es: 0x0000001f fs: 0x00000000 gs: 0x00000037
cr2: 0xb0000000

You do not release your operation queue in dealloc...
One suspect is the delegation pattern:
[request setDelegate:self];
If the self object is destroyed, and the request isn't, when the request 'completes', it will try to notify some garbage in memory, hence crash.
UPDATE: to patch this, add this code before canceling:
for (ASIHTTPRequest *request in queue.operations)
{
[request setDelegate: nil];
[request setDidFinishSelector: nil];
}

I think jv42 is correct about the cause. However, there's a handy helper for cleaning up delegates...
-(void)dealloc {
for (ASIHTTPRequest *request in queue.operations) {
[request clearDelegatesAndCancel];
}
[queue release];
[super dealloc];
}
Has anyone found a quicker method for this... maybe one that doesn't involve looping over the requests?

Make sure you are running a recent git version of ASIHTTPRequest - v1.7 contains a couple of race conditions that will causes crashes when cancelling requests.

I was having the same situation while running a ASINetworkQueue with multiple requests.
I removed the dealloc release for the queue, and the autorelease. I then applied Leah's excellent suggestion to loop through to nil the delegates. Then I put the queue's release in the queueRequestFinished delegate and it resolved my issue!
bulkQueue = [[ASINetworkQueue alloc] init];
[bulkQueue setQueueDidFinishSelector:#selector(queueRequestFinished:)];
-(void)queueRequestFinished:(ASINetworkQueue *)queue
{
for (ASIHTTPRequest *request in queue.operations)
{
[request setDelegate: nil];
[request setDidFinishSelector: nil];
}
}
Hope this helps someone out! :-)

Related

App crashes on iPhone 5 with iOS 6

The resolution center rejected my app because, as they say, it crashes on iPhone 5 with iOS 6.1.2.
I have an iPhone 4 with iOS 6.1.2 and it doesnt crash. I can't solve that problem!
They also wrote that the app crash when:
Launch the app
Login with Facebook.
App crashes when the device returns to the app.
Here the simbolicated crash log:
Last Exception Backtrace:
0 CoreFoundation 0x344ec3e2 0x3442a000 + 795618
1 libobjc.A.dylib 0x3c1dd95e 0x3c1d5000 + 35166
2 CoreFoundation 0x344eff2c 0x3442a000 + 810796
3 CoreFoundation 0x344ee648 0x3442a000 + 804424
4 CoreFoundation 0x34446204 0x3442a000 + 115204
5 Kick - Serie A 0x0007252c -[LetturaScrittura writeStringToFile:] (LetturaScrittura.m:26)
6 Kick - Serie A 0x0006e9da __25-[Profilo carica_profilo]_block_invoke (Profilo.m:314)
7 Kick - Serie A 0x0007e14a -[FBRequestConnection completeWithResults:orError:] (FBRequestConnection.m:1200)
8 Kick - Serie A 0x0007d56c -[FBRequestConnection completeWithResponse:data:orError:] (FBRequestConnection.m:983)
9 Kick - Serie A 0x0007b6aa __68-[FBRequestConnection startWithCacheIdentity:skipRoundtripIfCached:]_block_invoke_0 (FBRequestConnection.m:499)
10 Kick - Serie A 0x0007f38e -[FBURLConnection invokeHandler:error:response:responseData:] (FBURLConnection.m:163)
11 Kick - Serie A 0x0007f8f4 -[FBURLConnection connectionDidFinishLoading:] (FBURLConnection.m:233)
12 Foundation 0x34e28910 0x34d53000 + 874768
13 Foundation 0x34d68764 0x34d53000 + 87908
14 Foundation 0x34d68680 0x34d53000 + 87680
15 CFNetwork 0x341c964a 0x34141000 + 558666
16 CFNetwork 0x341c8d2e 0x34141000 + 556334
17 CFNetwork 0x341f100e 0x34141000 + 720910
18 CoreFoundation 0x34432ac8 0x3442a000 + 35528
19 CFNetwork 0x341f146e 0x34141000 + 722030
20 CFNetwork 0x3415545c 0x34141000 + 83036
21 CoreFoundation 0x344c18f2 0x3442a000 + 620786
22 CoreFoundation 0x344c1158 0x3442a000 + 618840
23 CoreFoundation 0x344bff2a 0x3442a000 + 614186
24 CoreFoundation 0x34433238 0x3442a000 + 37432
25 CoreFoundation 0x344330c4 0x3442a000 + 37060
26 GraphicsServices 0x38011336 0x3800c000 + 21302
27 UIKit 0x3634f2b4 0x362f8000 + 357044
28 Kick - Serie A 0x0006ac92 main (main.m:16)
29 libdyld.dylib 0x3c60ab1c 0x3c609000 + 6940
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3c6d1350 __pthread_kill + 8
1 libsystem_c.dylib 0x3c647fb2 pthread_kill + 54
2 libsystem_c.dylib 0x3c684366 abort + 90
3 libc++abi.dylib 0x3bc2cdda abort_message + 70
4 libc++abi.dylib 0x3bc2a094 default_terminate() + 20
5 libobjc.A.dylib 0x3c1dda58 _objc_terminate() + 144
6 libc++abi.dylib 0x3bc2a118 safe_handler_caller(void (*)()) + 76
7 libc++abi.dylib 0x3bc2a1b0 std::terminate() + 16
8 libc++abi.dylib 0x3bc2b626 __cxa_rethrow + 90
9 libobjc.A.dylib 0x3c1dd9b0 objc_exception_rethrow + 8
10 CoreFoundation 0x3443329c CFRunLoopRunSpecific + 452
11 CoreFoundation 0x344330c4 CFRunLoopRunInMode + 100
12 GraphicsServices 0x38011336 GSEventRunModal + 70
13 UIKit 0x3634f2b4 UIApplicationMain + 1116
14 Kick - Serie A 0x0006ac92 main (main.m:16)
15 libdyld.dylib 0x3c60ab1c start + 0
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x3c6c15d0 kevent64 + 24
1 libdispatch.dylib 0x3c5fcd22 _dispatch_mgr_invoke + 806
2 libdispatch.dylib 0x3c5f8374 _dispatch_mgr_thread + 32
Thread 2 name: WebThread
Thread 2:
0 libsystem_kernel.dylib 0x3c6c0e30 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3c6c0fd0 mach_msg + 48
2 CoreFoundation 0x344c12b6 __CFRunLoopServiceMachPort + 126
3 CoreFoundation 0x344c002c __CFRunLoopRun + 900
4 CoreFoundation 0x34433238 CFRunLoopRunSpecific + 352
5 CoreFoundation 0x344330c4 CFRunLoopRunInMode + 100
6 WebCore 0x3a432390 RunWebThread(void*) + 440
7 libsystem_c.dylib 0x3c62a0de _pthread_start + 306
8 libsystem_c.dylib 0x3c629fa4 thread_start + 4
Thread 3 name: com.apple.NSURLConnectionLoader
Thread 3:
0 libsystem_kernel.dylib 0x3c6c0e30 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3c6c0fd0 mach_msg + 48
2 CoreFoundation 0x344c12b6 __CFRunLoopServiceMachPort + 126
3 CoreFoundation 0x344c002c __CFRunLoopRun + 900
4 CoreFoundation 0x34433238 CFRunLoopRunSpecific + 352
5 CoreFoundation 0x344330c4 CFRunLoopRunInMode + 100
6 Foundation 0x34d80888 +[NSURLConnection(Loader) _resourceLoadLoop:] + 304
7 Foundation 0x34e0422c __NSThread__main__ + 968
8 libsystem_c.dylib 0x3c62a0de _pthread_start + 306
9 libsystem_c.dylib 0x3c629fa4 thread_start + 4
Thread 4 name: com.apple.CFSocket.private
Thread 4:
0 libsystem_kernel.dylib 0x3c6d1594 __select + 20
1 CoreFoundation 0x344c5474 __CFSocketManager + 676
2 libsystem_c.dylib 0x3c62a0de _pthread_start + 306
3 libsystem_c.dylib 0x3c629fa4 thread_start + 4
Thread 5:
0 libsystem_kernel.dylib 0x3c6d1d98 __workq_kernreturn + 8
1 libsystem_c.dylib 0x3c61fad6 _pthread_workq_return + 14
2 libsystem_c.dylib 0x3c61f7f2 _pthread_wqthread + 362
3 libsystem_c.dylib 0x3c61f680 start_wqthread + 4
Thread 6:
0 libsystem_kernel.dylib 0x3c6d1d98 __workq_kernreturn + 8
1 libsystem_c.dylib 0x3c61fad6 _pthread_workq_return + 14
2 libsystem_c.dylib 0x3c61f7f2 _pthread_wqthread + 362
3 libsystem_c.dylib 0x3c61f680 start_wqthread + 4
Thread 0 crashed with ARM Thread State (32-bit):
r0: 0x00000000 r1: 0x00000000 r2: 0x00000000 r3: 0x3e191524
r4: 0x00000006 r5: 0x3e191b78 r6: 0x1dd85ca4 r7: 0x2fd979f4
r8: 0x1dd85c80 r9: 0x00000300 r10: 0x00000000 r11: 0x3455b022
ip: 0x00000148 sp: 0x2fd979e8 lr: 0x3c647fb7 pc: 0x3c6d1350
cpsr: 0x00000010
Here's the LetturaScrittore method that makes the app crash (I use it to write on a .txt the email of the facebook user):
- (void)writeStringToFile:(NSString*)aString {
// Build the path, and create if needed.
NSString* filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* fileName = #"myTextFile.txt";
NSString* fileAtPath = [filePath stringByAppendingPathComponent:fileName];
if (![[NSFileManager defaultManager] fileExistsAtPath:fileAtPath]) {
[[NSFileManager defaultManager] createFileAtPath:fileAtPath contents:nil attributes:nil];
}
// The main act.
[[aString dataUsingEncoding:NSUTF8StringEncoding] writeToFile:fileAtPath atomically:YES];
}
The reason for the crash is that you don't actually pass a NSString object to writeStringToFile.
My mistake was on the facebook auth login: without the permission of the email, facebook return nothing, and the app crashes when trying to write the .txt file.

iOS App Crash on startup

The latest version of my app has started to crash on startup for some users. There is only 1 crash report in itunes which is included below. I have been unable to reproduce on any devices.
The changes between the two version are
Integrated two third party libraries (iNotify, openUDID)
Switched from the GCC compiler to the Apple LLVM 3.1 compiler (new libraries need arc support)
Compiled the new libraries's code with arc enabled, left arc disabled for the rest of the project.
I added 1 line to the didFinishLaunchingWithOptions in my appdelegate for iNotify. From the stack trace through I do not think its crashing in there.
At a bit of a loss where to go with this. Any help would be appreciated. Thanks!
Hardware Model: iPhone4,1
Process: MyAPP [3251]
Path: /var/mobile/Applications/228BBF42-A374-4773-8C18-EFA47CE98C02/MyAPP.app/MyAPP
Identifier: MyAPP
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2012-05-03 19:50:07.917 -0500
OS Version: iPhone OS 5.1 (9B179)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x3729e88f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x357a4259 objc_exception_throw + 33
2 CoreFoundation 0x372a1a9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x372a0915 ___forwarding___ + 301
4 CoreFoundation 0x371fb650 _CF_forwarding_prep_0 + 48
5 UIKit 0x33aa9f93 -[UIAlertView(Private) _popoutAnimationDidStop:finished:] + 855
6 UIKit 0x3395fc53 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 471
7 UIKit 0x3396557d -[UIViewAnimationState animationDidStop:finished:] + 53
8 QuartzCore 0x341fbc2f CA::Layer::run_animation_callbacks(void*) + 203
9 libdispatch.dylib 0x344f6ee7 _dispatch_main_queue_callback_4CF$VARIANT$mp + 195
10 CoreFoundation 0x372712ad __CFRunLoopRun + 1269
11 CoreFoundation 0x371f44a5 CFRunLoopRunSpecific + 301
12 CoreFoundation 0x371f436d CFRunLoopRunInMode + 105
13 GraphicsServices 0x32101439 GSEventRunModal + 137
14 UIKit 0x33978e7d UIApplicationMain + 1081
15 MyAPP 0x00002bfb main (main.m:14)
16 MyAPP 0x00002bb4 0x00002bb4
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x3571d32c __pthread_kill + 8
1 libsystem_c.dylib 0x3186b208 pthread_kill + 48
2 libsystem_c.dylib 0x31864298 abort + 88
3 libc++abi.dylib 0x34e70f64 abort_message + 40
4 libc++abi.dylib 0x34e6e346 _ZL17default_terminatev + 18
5 libobjc.A.dylib 0x357a4350 _objc_terminate + 140
6 libc++abi.dylib 0x34e6e3be _ZL19safe_handler_callerPFvvE + 70
7 libc++abi.dylib 0x34e6e44a std::terminate() + 14
8 libc++abi.dylib 0x34e6f81e __cxa_rethrow + 82
9 libobjc.A.dylib 0x357a42a2 objc_exception_rethrow + 6
10 CoreFoundation 0x371f4506 CFRunLoopRunSpecific + 398
11 CoreFoundation 0x371f4366 CFRunLoopRunInMode + 98
12 GraphicsServices 0x32101432 GSEventRunModal + 130
13 UIKit 0x33978e76 UIApplicationMain + 1074
14 MyAPP 0x00002bf4 main (main.m:14)
15 MyAPP 0x00002bac 0x00002bac
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x3570d3a8 kevent + 24
1 libdispatch.dylib 0x344f7f04 _dispatch_mgr_invoke + 708
2 libdispatch.dylib 0x344f7c22 _dispatch_mgr_thread + 30
Thread 2 name: WebThread
Thread 2:
0 libsystem_kernel.dylib 0x3570d004 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x3570d1fa mach_msg + 50
2 CoreFoundation 0x372723ec __CFRunLoopServiceMachPort + 120
3 CoreFoundation 0x37271124 __CFRunLoopRun + 876
4 CoreFoundation 0x371f449e CFRunLoopRunSpecific + 294
5 CoreFoundation 0x371f4366 CFRunLoopRunInMode + 98
6 WebCore 0x32eb40f0 _ZL12RunWebThreadPv + 396
7 libsystem_c.dylib 0x3182c72e _pthread_start + 314
8 libsystem_c.dylib 0x3182c5e8 thread_start + 0
Thread 3:
0 libsystem_kernel.dylib 0x3571dcd4 __workq_kernreturn + 8
1 libsystem_c.dylib 0x31826f36 _pthread_wqthread + 610
2 libsystem_c.dylib 0x31826cc8 start_wqthread + 0
Thread 4 name: com.apple.CFSocket.private
Thread 4:
0 libsystem_kernel.dylib 0x3571d570 __select + 20
1 CoreFoundation 0x3727663a __CFSocketManager + 726
2 libsystem_c.dylib 0x3182c72e _pthread_start + 314
3 libsystem_c.dylib 0x3182c5e8 thread_start + 0
Thread 5:
0 libsystem_kernel.dylib 0x3571dcd4 __workq_kernreturn + 8
1 libsystem_c.dylib 0x31826f36 _pthread_wqthread + 610
2 libsystem_c.dylib 0x31826cc8 start_wqthread + 0
Some additional code.
There is an alertview defined in the appdelegate as follows:
#import <UIKit/UIKit.h>
#class MyAPPViewController;
#interface MyAPPAppDelegate : NSObject <UIApplicationDelegate> {
UIViewController *rvc;
UIAlertView *m_cAlertControl;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
-(BOOL)shouldNag;
-(void)shouldEnableUI:(BOOL)pIsEnable;
-(void)updateRunCount;
#end
and a method implemented in the app delegate as follows:
-(void)shouldEnableUI:(BOOL)pIsEnable
{
if(NO == pIsEnable)
{
if (nil == m_cAlertControl) {
m_cAlertControl = [[UIAlertView alloc] init];
}
m_cAlertControl.backgroundColor = [UIColor clearColor];
m_cAlertControl.opaque = NO;
[m_cAlertControl setHidden:YES];
[m_cAlertControl show];
}
else {
if (nil != m_cAlertControl) {
[m_cAlertControl dismissWithClickedButtonIndex:0 animated:YES];
}
}
}
The View controller's make calls to the method like this:
[appDelegate shouldEnableUI:NO];
On seeing crash logs issue seems like call has been made to UIAlertViewDelegate after it has been released.
You need to release that in the controller where you are using alert -
-(void)dealloc {
self.alertView.delegate = nil; //setting delegate to nil
self.alertView = nil; //if you have defined alert as property
//other release statements of your controller
[super dealloc];
}
You can add some code of your app if you want some other information, or this is not the case with your app.
EDIT 1 -
-(void)dealloc {
m_cAlertControl.delegate = nil; //setting delegate to nil
[m_cAlertControl release];
//other release statements of your controller
[super dealloc];
}
I would say that this is the biggest pointer you have
[NSObject doesNotRecognizeSelector:] + 175
Looks like you have a missing selector method somewhere.

What caused this iPhone crash log?

Im somewhat stuck, and need to have this resolved because one of my apps is exhibiting random crashes which cannot always be reproduced. This is one of the crash logs:
Incident Identifier: 59865612-9F00-44EA-9474-2BF607AD662E
CrashReporter Key: bea17b7f4237e78a13ce60449d694621d0f16a44
Hardware Model: iPhone2,1
Process: APPNAME [82]
Path: /var/mobile/Applications/ACE9A1A2-F1BE-43E0-9775-1291723D4C4A/APPNAME.app/APPNAME
Identifier: APPNAME
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2011-05-21 19:10:27.893 +0100
OS Version: iPhone OS 4.3.3 (8J2)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000009
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x33b24c98 objc_msgSend + 16
1 Foundation 0x344507b4 __NSFireTimer + 112
2 CoreFoundation 0x3039ca40 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 8
3 CoreFoundation 0x3039eec4 __CFRunLoopDoTimer + 844
4 CoreFoundation 0x3039f83e __CFRunLoopRun + 1082
5 CoreFoundation 0x3032febc CFRunLoopRunSpecific + 224
6 CoreFoundation 0x3032fdc4 CFRunLoopRunInMode + 52
7 GraphicsServices 0x3448e418 0x3448a000 + 17432
8 GraphicsServices 0x3448e4c4 0x3448a000 + 17604
9 UIKit 0x33f3cd62 -[UIApplication _run] + 398
10 UIKit 0x33f3a800 UIApplicationMain + 664
11 APPNAME 0x00002d88 0x1000 + 7560
12 APPNAME 0x00002d3c 0x1000 + 7484
Thread 1 name: Dispatch queue: com.apple.libdispatch-manager
Thread 1:
0 libsystem_kernel.dylib 0x36100fbc kevent + 24
1 libdispatch.dylib 0x33d0b032 _dispatch_mgr_invoke + 706
2 libdispatch.dylib 0x33d0c03a _dispatch_queue_invoke + 86
3 libdispatch.dylib 0x33d0b5ea _dispatch_worker_thread2 + 186
4 libsystem_c.dylib 0x33e0a58a _pthread_wqthread + 258
5 libsystem_c.dylib 0x33e0abbc start_wqthread + 0
Thread 2 name: WebThread
Thread 2:
0 libsystem_kernel.dylib 0x360fdc00 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x360fd758 mach_msg + 44
2 CoreFoundation 0x3039d2b8 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x3039f562 __CFRunLoopRun + 350
4 CoreFoundation 0x3032febc CFRunLoopRunSpecific + 224
5 CoreFoundation 0x3032fdc4 CFRunLoopRunInMode + 52
6 WebCore 0x34c2627e RunWebThread(void*) + 382
7 libsystem_c.dylib 0x33e0930a _pthread_start + 242
8 libsystem_c.dylib 0x33e0abb4 thread_start + 0
Thread 3:
0 libsystem_kernel.dylib 0x360fdc00 mach_msg_trap + 20
1 libsystem_kernel.dylib 0x360fd758 mach_msg + 44
2 CoreFoundation 0x3039d2b8 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x3039f562 __CFRunLoopRun + 350
4 CoreFoundation 0x3032febc CFRunLoopRunSpecific + 224
5 CoreFoundation 0x3032fdc4 CFRunLoopRunInMode + 52
6 Foundation 0x343ea7f6 +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 206
7 Foundation 0x343dd382 -[NSThread main] + 38
8 Foundation 0x3444f5c6 __NSThread__main__ + 966
9 libsystem_c.dylib 0x33e0930a _pthread_start + 242
10 libsystem_c.dylib 0x33e0abb4 thread_start + 0
Thread 4 name: com.apple.CFSocket.private
Thread 4:
0 libsystem_kernel.dylib 0x360ffc60 __select + 20
1 CoreFoundation 0x303a28f2 __CFSocketManager + 582
2 libsystem_c.dylib 0x33e0930a _pthread_start + 242
3 libsystem_c.dylib 0x33e0abb4 thread_start + 0
Thread 5:
0 libsystem_kernel.dylib 0x361003ec __workq_kernreturn + 8
1 libsystem_c.dylib 0x33e0a6d8 _pthread_wqthread + 592
2 libsystem_c.dylib 0x33e0abbc start_wqthread + 0
Thread 6:
0 libsystem_kernel.dylib 0x361003ec __workq_kernreturn + 8
1 libsystem_c.dylib 0x33e0a6d8 _pthread_wqthread + 592
2 libsystem_c.dylib 0x33e0abbc start_wqthread + 0
Thread 7:
0 libsystem_kernel.dylib 0x361003ec __workq_kernreturn + 8
1 libsystem_c.dylib 0x33e0a6d8 _pthread_wqthread + 592
2 libsystem_c.dylib 0x33e0abbc start_wqthread + 0
Thread 8:
0 libsystem_kernel.dylib 0x361003ec __workq_kernreturn + 8
1 libsystem_c.dylib 0x33e0a6d8 _pthread_wqthread + 592
2 libsystem_c.dylib 0x33e0abbc start_wqthread + 0
Thread 0 crashed with ARM Thread State:
r0: 0x04246810 r1: 0x33738814 r2: 0x042b3704 r3: 0x00000000
r4: 0x00000001 r5: 0x00000001 r6: 0x00259330 r7: 0x2fdfeb30
r8: 0x002593d0 r9: 0x00000000 r10: 0x04241720 r11: 0x00000000
ip: 0x3fa3f4e8 sp: 0x2fdfea60 lr: 0x349077bb pc: 0x33dfcc98
cpsr: 0x280f0030
Can someone offer a suggestion as to what might be the cause ?
Thanks!
It looks like you have a timer firing and trying to send a message to an object that has been dealloc'ed.
Keyline here is: Exception Type: EXC_BAD_ACCESS (SIGBUS)
It occurs, when you are trying to access an object that has been released earlier. Since, you are trying to access an object in a timer's callback, what is possibly happening is that while the timer responds for an object, the object in question has been released.
You can track the object by enabling the NSZombie environment variable.
When you create a NSTimer it is critical that you hold on to the ref and then invalidate it if the object to be called goes away. Like so:
[self.bugZapTimer invalidate];
self.bugZapTimer = [NSTimer timerWithTimeInterval: 0.1
target: self
selector: #selector(bugZapTimer:)
userInfo: NULL
repeats: FALSE];
[[NSRunLoop currentRunLoop] addTimer:self.bugZapTimer forMode: NSDefaultRunLoopMode];
Then, in your dealloc method you must do:
[self.bugZapTimer invalidate];
self.bugZapTimer = nil;

StoreKit SKProductsRequest Crash

I use the following code to request a list of products as per the In-App Purchase Programming Guide. It used to work fine in my iPhone application, however now it crashes every time the product list is requested. The delegate method (void)productsRequest:(SKProductsRequest **)request didReceiveResponse:(SKProductsResponse **)response is never called.
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:#"my.product.identifier"]];
[request setDelegate:self];
[request start];
As I said, it worked perfectly fine, then just stopped working. This is the crash which occurs when the above code is called.
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000011
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x000034f8 objc_msgSend + 24
1 StoreKit 0x00003e18 -[SKProductsRequest handleFinishResponse:returningError:] + 40
2 StoreKit 0x000050c4 -[SKRequest _requestFinishedNotification:] + 152
3 Foundation 0x00019b9a _nsnote_callback + 150
4 CoreFoundation 0x0006c2de __CFXNotificationPost_old + 390
5 CoreFoundation 0x0001ab32 _CFXNotificationPostNotification + 122
6 Foundation 0x000048e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
7 AppSupport 0x0000bb42 -[CPDistributedNotificationCenter deliverNotification:userInfo:] + 38
8 AppSupport 0x0000cf66 _CPDNDeliverNotification + 198
9 AppSupport 0x0000ba4a _XDeliverNotification + 110
10 AppSupport 0x00002e82 migHelperRecievePortCallout + 122
11 CoreFoundation 0x000742ac __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 22
12 CoreFoundation 0x000761d6 __CFRunLoopDoSource1 + 158
13 CoreFoundation 0x0007718e __CFRunLoopRun + 574
14 CoreFoundation 0x0001e0bc CFRunLoopRunSpecific + 220
15 CoreFoundation 0x0001dfca CFRunLoopRunInMode + 54
16 GraphicsServices 0x00003f88 GSEventRunModal + 188
17 UIKit 0x00007b40 -[UIApplication _run] + 564
18 UIKit 0x00005fb8 UIApplicationMain + 964
19 myapp 0x00002fae main (main.m:13)
20 myapp 0x00002f58 start + 32
Thread 1:
0 libSystem.B.dylib 0x00034e84 kevent + 24
1 libSystem.B.dylib 0x00102a48 _dispatch_mgr_invoke + 88
2 libSystem.B.dylib 0x00102494 _dispatch_queue_invoke + 96
3 libSystem.B.dylib 0x00102634 _dispatch_worker_thread2 + 120
4 libSystem.B.dylib 0x0008b53c _pthread_wqthread + 392
5 libSystem.B.dylib 0x00082b6c start_wqthread + 0
Thread 2:
0 libSystem.B.dylib 0x00000ab0 mach_msg_trap + 20
1 libSystem.B.dylib 0x00002f94 mach_msg + 60
2 CoreFoundation 0x00074b18 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x000770e0 __CFRunLoopRun + 400
4 CoreFoundation 0x0001e0bc CFRunLoopRunSpecific + 220
5 CoreFoundation 0x0001dfca CFRunLoopRunInMode + 54
6 WebCore 0x0000370c RunWebThread(void*) + 552
7 libSystem.B.dylib 0x0008af80 _pthread_start + 364
8 libSystem.B.dylib 0x0007d014 thread_start + 0
Thread 3:
0 libSystem.B.dylib 0x00000ab0 mach_msg_trap + 20
1 libSystem.B.dylib 0x00002f94 mach_msg + 60
2 CoreFoundation 0x00074b18 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x000770e0 __CFRunLoopRun + 400
4 CoreFoundation 0x0001e0bc CFRunLoopRunSpecific + 220
5 CoreFoundation 0x0001dfca CFRunLoopRunInMode + 54
6 Foundation 0x0003c316 +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 210
7 Foundation 0x0000c612 -[NSThread main] + 42
8 Foundation 0x00092140 __NSThread__main__ + 908
9 libSystem.B.dylib 0x0008af80 _pthread_start + 364
10 libSystem.B.dylib 0x0007d014 thread_start + 0
Thread 4:
0 libSystem.B.dylib 0x00029f24 select$DARWIN_EXTSN + 20
1 CoreFoundation 0x0007aa54 __CFSocketManager + 340
2 libSystem.B.dylib 0x0008af80 _pthread_start + 364
3 libSystem.B.dylib 0x0007d014 thread_start + 0
I don't know what is causing the objc_msgSend crash, or how it is related to StoreKit. I also have no idea what I added or changed which caused this simple code to stop working.
A very likely explanation is whether the object you set as a delegate for the SKProductRequest object might have been deallocated already.
It is quite possible for the request to take a few seconds to complete, and this might be past the lifetime of your delegate object, so you may want to make sure it sticks around for long enough.
The answer above is technically correct but it is not complete. As Megastep said "the object you set as the delegate for the SKProductsRequest may have already been deallocated." Therefore you are sending a message to an object that has already been deallocated. Now onto the actual answer:
- (void)requestProUpgradeProductData {
NSSet *productIdentifiers = //Your Product IDs go here
productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];
productsRequest.delegate = self;
[productsRequest start];
// we will release the request object in the delegate callback
}
#pragma mark -
#pragma mark SKProductRequest Delegate Methods
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse(SKProductsResponse *)response {
self.products = response.products;
//NSLog(#"%i",[products count]);
proUpgradeProduct = [products count] == 4 ? [[products objectAtIndex:0] retain] : nil;
if (proUpgradeProduct)
{
//Do your stuff here...
}
for (NSString *invalidProductId in response.invalidProductIdentifiers)
{
//NSLog(#"Invalid product id: %#" , invalidProductId);
}
// finally release the reqest we alloc/init’ed in requestProUpgradeProductData
[productsRequest release];
[[NSNotificationCenter defaultCenter] postNotificationName:kInAppPurchaseManagerProductsFetchedNotification object:self userInfo:nil];
}
So basically as you can see above you do not need to release productsRequest because it is already being released in the delegate callback method. Again you do not need to call productsRequest release or set it Nil in viewDidUnload/dealloc method because that could cause a crash if you dismiss the view before the callback method gets called.
I'm using an object like a delegate. So in the deinit method of this object i remove the delegate a and crash has been fixed.
private var currentProductRequest: SKProductsRequest?
deinit {
if let r = currentProductRequest {
r.delegate = nil
r.cancel()
currentProductRequest = nil
}
}

How do I make sense of this crash report (SIGABRT)? Regarding parsing an XML file on another host computer + iPad

Basically, imagine this. I have an iPad, a Windows computer with the Apache HTTP server which is hosting an XML file, and a Wi-Fi network that connects them both together.
The XML parser I'm using is NSXMLParser.
In my - (void)parseXMLFileAtURL method this is my code.
NSError * error;
NSURLResponse * response;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://%#/UserBedData.xml",[appDelegate.hostipadd objectAtIndex:0]]] cachePolicy :NSURLRequestReloadIgnoringCacheData timeoutInterval:6.0];
[request setHTTPMethod:#"GET"];
NSData * responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error] ;
xmlParser = [[[NSXMLParser alloc] initWithData:responseData] autorelease];
[xmlParser setDelegate:self];
// Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
[xmlParser setShouldProcessNamespaces:NO];
[xmlParser setShouldReportNamespacePrefixes:NO];
[xmlParser setShouldResolveExternalEntities:NO];
[xmlParser parse];
If I have very little data in the XML file (which is on the Windows computer) the parsing works fine, and I would get the data and store them, etc. After parsing, I would request another file which is a .php file that would, when upon requested, delete('unlink') the XML file. Sort of for data consistency. The method goes like this.
- (void)parserDidEndDocument:(NSXMLParser *)parser
NSError * error;
NSURLResponse * response;
//HTTPREQUEST to delete send a GET request to the server to a PHP file with pw = md5hash of a password. This is to delete the XML file
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://%#/delete.php",[appDelegate.hostipadd objectAtIndex:0]]] cachePolicy :NSURLRequestReloadIgnoringCacheData timeoutInterval:5.0];
NSData * responseData = [[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error] autorelease] ;}
Now, when it successfuly parses it, I can see on the PC that the XML file has been deleted.
But here comes the problem, when I have several hundreds of records in the XML file, I'm thinking that it takes too long to parses the data and crashes for whatever reason. The error log is below. I'm sure that the error occurs WHILE parsing because the XML file was NOT deleted. This means that the parserDidEndDocument method was not invoked.
How should I solve this?
Date/Time: 2010-08-20 13:40:30.047 +0800
OS Version: iPhone OS 3.2.1 (7B405)
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libSystem.B.dylib 0x000790a0 __kill + 8
1 libSystem.B.dylib 0x00079090 kill + 4
2 libSystem.B.dylib 0x00079082 raise + 10
3 libSystem.B.dylib 0x0008d20a abort + 50
4 libstdc++.6.dylib 0x00044a1c __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x000057c4 _objc_terminate + 104
6 libstdc++.6.dylib 0x00042dee __cxxabiv1::__terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x00042e42 std::terminate() + 10
8 libstdc++.6.dylib 0x00042f12 __cxa_throw + 78
9 libobjc.A.dylib 0x000046a4 objc_exception_throw + 64
10 CoreFoundation 0x00090c6e +[NSException raise:format:arguments:] + 74
11 CoreFoundation 0x00090d38 +[NSException raise:format:] + 28
12 UIKit 0x0010327a -[UIViewController _loadViewFromNibNamed:bundle:] + 178
13 UIKit 0x0006317a -[UIViewController loadView] + 74
14 UIKit 0x000693f2 -[UITableViewController loadView] + 46
15 UIKit 0x0005b2c0 -[UIViewController view] + 24
16 MedicalBed 0x0000ce7e -[SelectionScreen btnRefresh:] (SelectionScreen.m:188)
17 CoreFoundation 0x00025166 -[NSObject performSelector:withObject:withObject:] + 18
18 UIKit 0x000550ce -[UIApplication sendAction:to:from:forEvent:] + 78
19 UIKit 0x0005506e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 26
20 UIKit 0x00055040 -[UIControl sendAction:to:forEvent:] + 32
21 UIKit 0x00054d92 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 350
22 UIKit 0x000553e0 -[UIControl touchesEnded:withEvent:] + 336
23 UIKit 0x00053db6 -[UIWindow _sendTouchesForEvent:] + 322
24 UIKit 0x000536fe -[UIWindow sendEvent:] + 74
25 UIKit 0x0004f320 -[UIApplication sendEvent:] + 260
26 UIKit 0x0004ec8c _UIApplicationHandleEvent + 4772
27 GraphicsServices 0x00003b2c PurpleEventCallback + 660
28 CoreFoundation 0x00022d96 CFRunLoopRunSpecific + 2214
29 CoreFoundation 0x000224da CFRunLoopRunInMode + 42
30 GraphicsServices 0x000030d4 GSEventRunModal + 108
31 GraphicsServices 0x00003180 GSEventRun + 56
32 UIKit 0x0000342a -[UIApplication _run] + 374
33 UIKit 0x00001954 UIApplicationMain + 636
34 MedicalBed 0x0000219c main (main.m:14)
35 MedicalBed 0x00002150 start + 32
Thread 1:
0 libSystem.B.dylib 0x00001668 mach_msg_trap + 20
1 libSystem.B.dylib 0x00003734 mach_msg + 44
2 CoreFoundation 0x0002296e CFRunLoopRunSpecific + 1150
3 CoreFoundation 0x000224da CFRunLoopRunInMode + 42
4 WebCore 0x0000268a RunWebThread(void*) + 286
5 libSystem.B.dylib 0x0007a786 _pthread_start + 242
6 libSystem.B.dylib 0x00070070 thread_start + 0
Thread 2:
0 libSystem.B.dylib 0x00001668 mach_msg_trap + 20
1 libSystem.B.dylib 0x00003734 mach_msg + 44
2 CoreFoundation 0x0002296e CFRunLoopRunSpecific + 1150
3 CoreFoundation 0x000224da CFRunLoopRunInMode + 42
4 Foundation 0x00017a4c +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 164
5 Foundation 0x00010bca -[NSThread main] + 38
6 Foundation 0x0007ccf8 __NSThread__main__ + 896
7 libSystem.B.dylib 0x0007a786 _pthread_start + 242
8 libSystem.B.dylib 0x00070070 thread_start + 0
Thread 3:
0 libSystem.B.dylib 0x00025968 select$DARWIN_EXTSN + 20
1 CoreFoundation 0x00072d7c __CFSocketManager + 552
2 libSystem.B.dylib 0x0007a786 _pthread_start + 242
3 libSystem.B.dylib 0x00070070 thread_start + 0
Thread 0 crashed with ARM Thread State:
r0: 0x00000000 r1: 0x00000000 r2: 0x00000001 r3: 0x381ac6d0
r4: 0x00000006 r5: 0x087411cc r6: 0x2fffe910 r7: 0x2fffe920
r8: 0x38029708 r9: 0x00000065 r10: 0x00000000 r11: 0x30ed3644
ip: 0x00000025 sp: 0x2fffe920 lr: 0x3167c097 pc: 0x3167c0a0
cpsr: 0x000f0010
It doesn't seem like this directly relates to XML parsing. Instead it appears to be loading of a view that have some inconsistencies:
Looking at line 14-16 of thread 0, it happens directly as a result of loading a view as a response to handling a button push in btnRefresh: (line 188 of SelectionScreen.m).
14 UIKit 0x000693f2 -[UITableViewController loadView] + 46
15 UIKit 0x0005b2c0 -[UIViewController view] + 24
16 MedicalBed 0x0000ce7e -[SelectionScreen btnRefresh:] (SelectionScreen.m:188)
This method calls a view method which triggers the load of the nib. And this is where it all goes wrong.
So, try to check your nib file for inconsistencies.
Another hint pointing at this, is that thread 2 still have some active NSURLConnection. Unless you have more than one connection, this could point to the XML still being loaded.
Hope this helps.