Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView crashing on second pdf load request

I have a UIWebView I'm using to show several small PDF's. The user selects a news article from a table and then the article(PDF) is loaded in a UIWebView on the same screen. The first load always goes just fine. Then the next item I select (no matter which one) crashes the app.

This is how I'm loading each article:

NSString *filePath = [[NSBundle mainBundle] pathForResource:articleFileName ofType:@"pdf"];
[articleView stopLoading];
[articleView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];

The crash occurs after the loadRequest line.
The crash gives no error information. Other than:

All Exceptions {} 0x3629f000

Catchpoint 3 (exception thrown).(gdb)

It just crashes to main(). I have verified in the debugger that it is using the correct file path on each request.

I have NSZombies running and I have breakpoints set for all exceptions.

like image 467
Dancreek Avatar asked Dec 15 '11 18:12

Dancreek


2 Answers

I have this exact problem as well. Big thanks to Steve for helping me narrow it down even further, my exception is the same as his.

Do you have break on all exceptions set? I found that if I disable that breakpoint, it doesn't crash any more. Which got me thinking it was just some bug in the new debugger or iOS version? The other thing that got me thinking that was that this crash does not occur when I run on a device with iOS 4.3.x or the 4.3 simulator.

like image 116
Bek Avatar answered Nov 11 '22 02:11

Bek


I'm seeing something similar - both while freeing a webview after loading a PDF or while loading html after loading a PDF. It appears to be rdar://10431759 (see http://openradar.appspot.com/10431759 ). I don't have a way to work around it. I can reproduce it by loading a pdf and then loading the html string @"<div></div>", so it doesn't appear to be a delegate issue.

If you type "bt" into the gdb console, you may get the real stacktrace, including:

#0  0x37ccd1c8 in objc_exception_throw ()
#1  0x381817b8 in +[NSException raise:format:arguments:] ()
#2  0x381817b8 in +[NSException raise:format:arguments:] ()
#3  0x381817da in +[NSException raise:format:] ()
#4  0x35462628 in -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] ()
#5  0x35462296 in -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] ()
#6  0x31fc3448 in -[UIWebPDFView _removeBackgroundImageObserverIfNeeded:] ()
#7  0x31fc36a8 in -[UIWebPDFView dealloc] ()
#8  0x37cc90c4 in _objc_rootRelease ()
#9  0x31dd2614 in -[UIWebPDFViewHandler clearAllViews] ()
#10 0x31d76708 in -[UIWebPDFViewHandler _replacePDFViewIfPresentWithWebDocView:] ()
#11 0x31d766a6 in -[UIWebPDFViewHandler _removePDFViewIfWebDocViewIsNotPDF:] ()
#12 0x31d76644 in -[UIWebBrowserView webView:didFirstVisuallyNonEmptyLayoutInFrame:] ()

When debugging on the device, you can type "frame 0" and "po $r0" to see the exception message: (I think it's "po $eax" in the simulator.)

(gdb) frame 0
#0  0x37ccd1c8 in objc_exception_throw ()
(gdb) po $r0
Cannot remove an observer <UIWebPDFView 0x4a3200> for the key path "backgroundImage" from <UIPDFPageView 0x4a4bf0> because it is not registered as an observer.

Edit: This problem only seems to occur when I have "Break on throw" turned on for Objective-C exceptions.

like image 45
Steve Avatar answered Nov 11 '22 01:11

Steve