Patrick
Patrick

Reputation: 727

Xamarin Unified IOS WKWebView Crash

I am having some trouble using a WKWebView with the new Xamarin Unified iOS API, it crashes on load with a EXC_BAD_ACCESS (SIGABRT) - KERN_INVALID_ADDRESS exception (have to dig through the phone logs for that, nothing shows up in visual studio.

I was hoping someone had some experience with this. The below appears to be the offending code, which worked fine in the classic API (albeit with minor changes due to the API differences). If I comment out the 3 WKWebView lines, and the line that adds it to the controller, the app runs. To note: Window, Controller, and WKWebView are all parameters of the appdelegate class.

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    Window = new UIWindow(UIScreen.MainScreen.Bounds);
    Window.BackgroundColor = UIColor.White;
    Window.MakeKeyAndVisible();

    Controller = new UIViewController();
    Controller.View.AutosizesSubviews = true;
    Window.RootViewController = Controller;

    var wkConfig = new WKWebViewConfiguration();
    WKWebView = new WKWebView(new CGRect(0, 20, (float)UIScreen.MainScreen.Bounds.Width, (float)UIScreen.MainScreen.Bounds.Height - 20), wkConfig);
    WKWebView.LoadRequest(new NSUrlRequest(new NSUrl(RazorRouting.GetRootUrl())));

    Controller.View.AddSubview(WKWebView);

    return true;
}

And here is the relevant section of the crash report (the crashing thread stack trace)

Incident Identifier: 4C8B4F14-0412-48AC-A94A-70BEDFB07A07
CrashReporter Key:   35ac6193617557278e0d2ddbc984b0442b429f07
Hardware Model:      iPhone5,3
Process:             OurAppNameiOS [2311]
Path:                /private/var/mobile/Containers/Bundle/Application/003A0100-F79D-48A5-BEB5-    24CC9568E49A/OurAppNameiOS.app/OurAppNameiOS
Identifier:          com.OurApp.OurAppName
Version:             1.0 (1.0)
Code Type:           ARM (Native)
Parent Process:      launchd [1]

Date/Time:           2014-10-28 07:57:50.403 -0400
Launch Time:         2014-10-28 07:57:45.692 -0400
OS Version:          iOS 8.1 (12B411)
Report Version:      105

Exception Type:  EXC_BAD_ACCESS (SIGABRT)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000004
Triggered by Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x3766fdfc __pthread_kill + 8
1   libsystem_pthread.dylib         0x376edd32 pthread_kill + 58
2   libsystem_c.dylib               0x3760f904 abort + 72
3   OurAppNameiOS   0x00c15866 0xe1000 + 11749478
4   OurAppNameiOS   0x00c1de5c 0xe1000 + 11783772
5   libsystem_platform.dylib        0x376e9878 _sigtramp + 40
6   WebKit                          0x2d6820a6 -[WKWebView initWithFrame:configuration:] + 570
7   OurAppNameiOS   0x00bd80c0 0xe1000 + 11497664
8   OurAppNameiOS   0x00bb6ba4 0xe1000 + 11361188
9   OurAppNameiOS   0x000eb4b0 0xe1000 + 42160
10  OurAppNameiOS   0x0029d5a0 0xe1000 + 1820064
11  OurAppNameiOS   0x00c20058 0xe1000 + 11792472
12  OurAppNameiOS   0x00c5d296 0xe1000 + 12042902
13  OurAppNameiOS   0x00bf0a5c 0xe1000 + 11598428
14  OurAppNameiOS   0x00bf1584 0xe1000 + 11601284
15  UIKit                           0x2cd6c71c -[UIApplication     _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 280
16  UIKit                           0x2cf615aa -[UIApplication     _callInitializationDelegatesForMainScene:transitionContext:] + 2354
17  UIKit                           0x2cf63af6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1370
18  UIKit                           0x2cf6e374 __84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 32
19  UIKit                           0x2cf62384 -[UIApplication workspaceDidEndTransaction:] + 128
20  FrontBoardServices              0x2ffcf0e6 __31-[FBSSerialQueue performAsync:]_block_invoke     + 10
21  CoreFoundation                  0x2980939a __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 10
22  CoreFoundation                  0x2980865c __CFRunLoopDoBlocks + 212
23  CoreFoundation                  0x29806dde __CFRunLoopRun + 758
24  CoreFoundation                  0x2975520c CFRunLoopRunSpecific + 472
25  CoreFoundation                  0x2975501e CFRunLoopRunInMode + 102
26  UIKit                           0x2cd663ea -[UIApplication _run] + 554
27  UIKit                           0x2cd611cc UIApplicationMain + 1436
28  OurAppNameiOS   0x00bd8e00 0xe1000 + 11501056
29  OurAppNameiOS   0x00bada10 0xe1000 + 11323920
30  OurAppNameiOS   0x00bad9d0 0xe1000 + 11323856
31  OurAppNameiOS   0x000ea27c 0xe1000 + 37500
32  OurAppNameiOS   0x0029d5a0 0xe1000 + 1820064
33  OurAppNameiOS   0x00c20058 0xe1000 + 11792472
34  OurAppNameiOS   0x00c5d296 0xe1000 + 12042902
35  OurAppNameiOS   0x00c60516 0xe1000 + 12055830
36  OurAppNameiOS   0x00c60354 0xe1000 + 12055380
37  OurAppNameiOS   0x00c0ead4 0xe1000 + 11721428
38  OurAppNameiOS   0x00cb18c4 0xe1000 + 12388548
39  OurAppNameiOS   0x00bf2700 0xe1000 + 11605760
40  libdyld.dylib                   0x375a9aac start + 0

Upvotes: 0

Views: 998

Answers (1)

Brendan Zagaeski
Brendan Zagaeski

Reputation: 2882

This is likely caused by a bug in the Visual Studio build process for Xamarin.iOS Unified API projects that causes problems for the special Unified nfloat primitive type (see https://bugzilla.xamarin.com/show_bug.cgi?id=23868#c14).

I've filed a second bug specifically for this WKWebView crash here: https://bugzilla.xamarin.com/show_bug.cgi?id=24151. I suspect this new bug will eventually be resolved as a duplicate of the older bug.

Upvotes: 1

Related Questions