Imran Raheem Imran Raheem - 5 months ago 33
Objective-C Question

App Crashes when NavigationController is popped!

Below is what I copy/pasted from the Crash Log sent by the client. I am unable to understand what does that mean :s

Apparently it looks like the app crashed when navigating back to a previous screen (and that's what client has reported). What is UIWebDocumentView here?

I need to resolve the crash but I'm stuck here so any help is highly appreciated.

P.S. I'm using iphone sdk 3.0.

Date/Time: 2009-09-29 18:16:28.458 -0400
OS Version: iPhone OS 3.0 (7A341)
Report Version: 104

Exception Codes: KERN_INVALID_ADDRESS at 0xbbadbeef
Crashed Thread: 4

Thread 4 Crashed:

0 WebCore 0x3588dd74 __ZL17_WebTryThreadLockb + 288
1 WebCore 0x3588e4c0 __ZL18_WebThreadAutoLockv + 52
2 UIKit 0x30aea484 -[UIWebDocumentView _responderForBecomeFirstResponder] + 8
3 UIKit 0x30978b34 -[UINavigationTransitionView transition:fromView:toView:] + 200
4 UIKit 0x30978a54 -[UINavigationTransitionView transition:toView:] + 24
5 UIKit 0x30974470 -[UINavigationController _startTransition:fromViewController:toViewController:] + 1604
6 UIKit 0x30973d90 -[UINavigationController _startDeferredTransitionIfNeeded] + 256
7 UIKit 0x309a7468 -[UINavigationController _popViewControllerWithTransition:allowPoppingLast:] + 400
8 UIKit 0x309a72c8 -[UINavigationController popViewControllerAnimated:] + 32
9 Snocell 0x0002ae00 0x1000 + 171520
10 Foundation 0x30554062 -[NSThread main] + 42
11 Foundation 0x305023f2 __NSThread__main__ + 852
12 libSystem.B.dylib 0x31d705a0 _pthread_body + 20


Ok, i guess i found the solution. Sharing it in case someone else gets into the same situation:

EXC_BAD_ACCESS (SIGSEGV) KERN_INVALID_ADDRESS means that the virtual address you're refererencing is not in the page tables or you don't have access. It's a virtual address that you're not allowed to access. For your example address address 0x67696c69 it's likely that this is something that is not a pointer that was treated like a pointer; or your data structure that contains the pointer was free'd and overwritten with other data.

And, then i see WebCore in the stack trace in the log (WebCore is a component in iPhone WebKit -

So, what I was doing here, dispalying a website in UIWebView and before it could load completely, popping back to previous view controllers and it CRASHED.

I found that UIWebView needs to have its delegate cleared before you release it; otherwise, if a web request completes after you release the UIWebView, it attempts to call back to the delegate and causes the application to crash.

SOLUTION: I added the following code before popping view controller and it's working now :)

if (webView.loading)
    [webView stopLoading];
webView.delegate = nil;