Crash in UIKit related to WebView

2

I have a random crash in UIKit that happend a couple of times already.

It crashes with EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000d

Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x30e08f46 objc_msgSend + 5
1  UIKit                          0x26d1790d -[_UIWebViewScrollViewDelegateForwarder forwardInvocation:] + 140
2  CoreFoundation                 0x23654def ___forwarding___ + 354
3  CoreFoundation                 0x23586df8 _CF_forwarding_prep_0 + 24
4  UIKit                          0x26b5a6fd -[UIScrollView _getDelegateZoomView] + 84
5  UIKit                          0x26b5a635 -[UIScrollView _zoomScaleFromPresentationLayer:] + 24
6  UIKit                          0x26b5a5ed -[UIWebDocumentView _zoomedDocumentScale] + 64
7  UIKit                          0x26b5a13d -[UIWebDocumentView _layoutRectForFixedPositionObjects] + 104
8  UIKit                          0x26b59f97 -[UIWebDocumentView _updateFixedPositionedObjectsLayoutRectUsingWebThread:synchronize:] + 38
9  UIKit                          0x26b5c3e5 -[UIWebDocumentView _updateFixedPositioningObjectsLayoutAfterScroll] + 28
10 UIKit                          0x26b5c3c1 -[UIWebBrowserView _updateFixedPositioningObjectsLayoutAfterScroll] + 56
11 CoreFoundation                 0x2360a281 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
12 CoreFoundation                 0x2356652d _CFXNotificationPost + 1784
13 Foundation                     0x24296189 -[NSNotificationCenter postNotificationName:object:userInfo:] + 72
14 UIKit                          0x27171dd7 -[UIInputWindowController postEndNotifications:withInfo:] + 554
15 UIKit                          0x271732ed __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke595 + 368
16 UIKit                          0x26b44b05 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 308
17 UIKit                          0x26b4471d -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 184
18 UIKit                          0x26b4462f -[UIViewAnimationState animationDidStop:finished:] + 66
19 QuartzCore                     0x2653d2d9 CA::Layer::run_animation_callbacks(void*) + 236
20 libdispatch.dylib              0x3135c7a7 _dispatch_client_callout + 22
21 libdispatch.dylib              0x3135ffa3 _dispatch_main_queue_callback_4CF + 718
22 CoreFoundation                 0x236179d1 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
23 CoreFoundation                 0x236160d1 __CFRunLoopRun + 1512
24 CoreFoundation                 0x23564211 CFRunLoopRunSpecific + 476
25 CoreFoundation                 0x23564023 CFRunLoopRunInMode + 106
26 GraphicsServices               0x2a95d0a9 GSEventRunModal + 136
27 UIKit                          0x26b701d1 UIApplicationMain + 1440
28 MY_PROJECT                     0x000842cf main (main.m:16)

It looks like it is related to UIWebView, but I have no clue what happened - any help is appreciated The crash seems to be known in China ...

ios
objective-c
uiwebview
asked on Stack Overflow Nov 28, 2014 by dogsgod

2 Answers

1

As mentioned by @ NilsHolgerson I had a some issues with notifications. The most probable reason was a notification that was not properly removed and that did retain a ViewController that was detached otherwise:

   [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
                [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
                ...

The solution looks as follows:

__weak typeof(self) weakself = self;
__block NSObject *reference = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
                [[NSNotificationCenter defaultCenter] removeObserver:reference];
                ...
answered on Stack Overflow Dec 8, 2014 by dogsgod
1

The deeply reason of this issues is: Container ViewController has been released when webView doing some animations.

So the directly solution is set webView's delegate to nil when ViewControllers dealloc.

Of course if you release VC appropriately as @dogsgod do is also a solution.

answered on Stack Overflow Apr 24, 2017 by kimimaro

User contributions licensed under CC BY-SA 3.0