MOE app is crashing

I’m struggling how to debug crash somewhere inside swift code in the Charts Pod library. It is mostly happening on iPhone emulator:

This started to happen after I added Crashlytics Pod, but other than that I can’t find any clues. So, I’d appreciate any help how to debug or get to the bottom of this.

I wasn’t been able to catch the error from the Java code, but Crashlytics gets this trace:

Crashed: main
0  libswiftFoundation.dylib       0x19a8e301 _TFs26_forceBridgeFromObjectiveCurFTPs9AnyObject_Mx_x + 481
1  libswiftFoundation.dylib       0x19a90508 _TFZFE10FoundationVs10Dictionary36_unconditionallyBridgeFromObjectiveCFGSqCSo12NSDictionary_GS0_xq__U_FTP_P_GSpV10ObjectiveC8ObjCBool__T_ + 120
2  libswiftFoundation.dylib       0x19afc874 _TPA__TFZFE10FoundationVs10Dictionary36_unconditionallyBridgeFromObjectiveCFGSqCSo12NSDictionary_GS0_xq__U_FTP_P_GSpV10ObjectiveC8ObjCBool__T_ + 84
3  libswiftFoundation.dylib       0x19a8e42f _TTRg0_Rxs8HashablerXFo_iP_iP_dGSpV10ObjectiveC8ObjCBool___XFdCb_dPs9AnyObject_dPS2__dGSpS1____ + 287
4  CoreFoundation                 0x181ffb5c __NSDictionaryEnumerate + 828
5  libswiftFoundation.dylib       0x19a8ffb9 _TZFE10FoundationVs10Dictionary36_unconditionallyBridgeFromObjectiveCfGSqCSo12NSDictionary_GS0_xq__ + 617
6  Charts                         0x14c2763c _TToFC6Charts20BarLineChartViewBase12observeValuefT10forKeyPathGSqSS_2ofGSqP__6changeGSqGVs10DictionaryVSC19NSKeyValueChangeKeyP___7contextGSqSv__T_ + 268
7  Foundation                     0x177dbdec NSKeyValueNotifyObserver + 351
8  Foundation                     0x177db687 NSKeyValueDidChange + 495
9  Foundation                     0x178bcb95 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:usingBlock:] + 986
10 Foundation                     0x177a0b01 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 60
11 Foundation                     0x17860bfb _NSSetRectValueAndNotify + 324
12 UIKit                          0x1528803d -[UIView(Geometry) _applyISEngineLayoutValuesToBoundsOnly:] + 608
13 UIKit                          0x1528836a -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 123
14 CoreFoundation                 0x182080b2 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
15 CoreFoundation                 0x18207fcf -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 335
16 UIKit                          0x15286be7 -[UIView(Geometry) resizeSubviewsWithOldSize:] + 184
17 UIKit                          0x15bafe76 -[UIView(AdditionalLayoutSupport) _is_layout] + 161
18 UIKit                          0x152935d0 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 1045
19 UIKit                          0x152a4ab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
20 QuartzCore                     0x1937abf8 -[CALayer layoutSublayers] + 146
21 QuartzCore                     0x1936e440 CA::Layer::layout_if_needed(CA::Transaction*) + 366
22 UIKit                          0x15292928 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1509
23 UIKit                          0x15299239 +[UIView(Animation) performWithoutAnimation:] + 90
24 UIKit                          0x1534d718 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 1161
25 UIKit                          0x1534d7e2 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
26 UIKit                          0x153212b0 -[UITableView _updateVisibleCellsNow:isRecursive:] + 3295
27 UIKit                          0x15356b64 -[UITableView _performWithCachedTraitCollection:] + 110
28 UIKit                          0x1533d3be -[UITableView layoutSubviews] + 222
29 UIKit                          0x152a4ab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
30 QuartzCore                     0x1937abf8 -[CALayer layoutSublayers] + 146
31 QuartzCore                     0x1936e440 CA::Layer::layout_if_needed(CA::Transaction*) + 366
32 UIKit                          0x15292928 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1509
33 UIKit                          0x153c28b1 -[UINavigationController _layoutViewController:] + 1625
34 UIKit                          0x153c16df -[UINavigationController _layoutTopViewController] + 341
35 UIKit                          0x153bea25 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 921
36 UIKit                          0x156a4ad8 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 418
37 UIKit                          0x156a4e3a -[UINavigationTransitionView _cleanupTransition] + 766
38 UIKit                          0x1526cbd5 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 222
39 UIKit                          0x152687d2 +[UIViewAnimationState popAnimationState] + 307
40 UIKit                          0x156a484e -[UINavigationTransitionView transition:fromView:toView:] + 2808
41 UIKit                          0x153c395b -[UINavigationController _startTransition:fromViewController:toViewController:] + 3314
42 UIKit                          0x153c3ef9 -[UINavigationController _startDeferredTransitionIfNeeded:] + 874
43 UIKit                          0x153c4fdb -[UINavigationController __viewWillLayoutSubviews] + 58
44 UIKit                          0x155bbdd7 -[UILayoutContainerView layoutSubviews] + 223
45 UIKit                          0x152a4ab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
46 QuartzCore                     0x1937abf8 -[CALayer layoutSublayers] + 146
47 QuartzCore                     0x1936e440 CA::Layer::layout_if_needed(CA::Transaction*) + 366
48 QuartzCore                     0x1936e2be CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
49 QuartzCore                     0x192fc318 CA::Context::commit_transaction(CA::Transaction*) + 280
50 QuartzCore                     0x193293ff CA::Transaction::commit() + 475
51 QuartzCore                     0x19329d6f CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 113
52 CoreFoundation                 0x1821d267 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
53 CoreFoundation                 0x1821d1d7 __CFRunLoopDoObservers + 391
54 CoreFoundation                 0x182018a6 CFRunLoopRunSpecific + 454
55 UIKit                          0x151d9aea -[UIApplication _run] + 434
56 UIKit                          0x151dfc68 UIApplicationMain + 159
57 MOE                            0x16f8605d ffi_call_unix64 + 85
58 MOE                            0x16f86a00 ffi_call_int + 763
59 MOE                            0x16f81c15 std::__1::function<void (unsigned int, _ffi_type**, void**)>::operator()(unsigned int, _ffi_type**, void**) const + 61
60 MOE                            0x16f81ae9 ValueConverter<(ValueConverterKind)1>::ValueConverter(ValueConverter<(ValueConverterKind)1>::Descriptor const&, std::__1::function<void (unsigned int, _ffi_type**, void**)>) + 273
61 MOE                            0x16f829f5 javaToNativeCallHandler(ffi_cif*, void*, void**, void*) + 757
62 MOE                            0x16f86c79 ffi_closure_unix64_inner + 487
63 MOE                            0x16f86202 ffi_closure_unix64 + 72
64 CoreSymbolication              0x2e1971cb (Missing)
65 ???                            0x0 (Missing)
66 libGSFontCache.dylib           0x200000008 (Missing)

Updated to MOE 1.3 release, but issue still persist. :frowning:

Could you please create a minimal test project for us that exhibits this issue? Then we could take a look and see what could be causing the problem.

To debug it yourself, you can try to do the following:

  • Add the standard Java debug parameters to the Xcode command line:
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
  • Set breakpoints in the Java IDE and in Xcode
  • Launch the app from Xcode
  • Attach from Java IDE using remote application connection

This way both your Java and your native breakpoints will be hit.

Note, that if you want to do this on a real device and not the simulator, before attaching to port 5005 from your Java IDE, you need to proxy that port from your device to the host. You can do that with the following command:

cd ~/.moe/moe-sdk-1.3.0/tools/
java -jar ios-device.jar --debug=5005

With MOE 1.3 we released the SImpleCharts sample, that should be using the same swift Charts library as you. You could try to fork that repo, and “break” it, so we have a test case to debug.

Does this issue happen with every simulator version (iOS 9, iOS 10), or just a specific one?

It only occurs on iphone simulator, but working on real ipad (ios 9.x) and ipad simulator (ios 10.x), or at least it doesn’t occurs immediately. I’ll see if I could isolate issue in a smaller project, but that’s not easy.

From the stacktrace above it isn’t obvious it is related to java or more code (last frame has something about swift to objc bridge) and I can’t get xcode to show me the sources for the Charts’s swift code where this crash occurs. The error seem to be on UI thread, so should be related to refreshing UI.

Previously MOE used to show me java stack trace, but not anymore. I though it was related to adding Crashlytics, but it seem the same after I removed Crashlytics.

Could you please elaborate exactly when and where MOE was giving you stacktrace that does not happen anymore? If there is a bug here, we would like to fix it.

Previously when something crashed, MOE showed me some Java stack trace on IDEconsole in the launch view. Admittedly, those crashes were originating from the Java code.

Now, it look like, my Java code that created views and table cells had completed. Then iOS TableView somehow got kicked to refresh/reload data and it triggered UI components or view to refresh. That’s where Chart’s swift code get invoked. At least that’s my current theory. So, I need to figure out to bring in Swift sources that came with Chart’s Pod and see how to step trough that or set break points in Swift.

Gergely, I expanded SimpleChart project with chunks of my app and managed to reproduce issue there. In this case it works and shows chart in emulator for iphone5, but fail for ipad Air.

Also it doesn’t show Swift source code where it is failing (same as with my project) and I can’t figure out why.

See link to download project below (since it is google drive, you may have to request access for download).

https://drive.google.com/file/d/0B56Yc_XO11-dbmVqYWtSMkVUSTQ/view?usp=sharing

Thank you again for your help
Eugene

Sorry to poke on this again, were you been able to reproduce issue with my project? I’m looking for any clues how I could debug this on my side and if there is some way to see the swift/objc code that it is crashing in? Right now xcode debugger is showing me asm code.

Updated all to MOE 1.3.2 and still getting the same error. I wonder if I have to regenerate bindings for swift Charts library?

Hi Eugene,

we checked the sample, and even ported it completely to Swift to see if it would crash there as well. It turned out, that Swift is incompatible with our trick to get MOE running on the x86-64 simulator.

The standard ART backends use 32 bit addresses even on 64 bit platforms. On x86-64 we use a “pagezero” trick in the linker flags to make it possible for us to map the OAT image to the right place in memory. As it turns out, this trick is incompatible with the current Swift language implementation.

This issue only affects the 64 bit simulators, 32 bit simulators and 32 and 64 bit ARM hardware will work as expected. So the workaround is to use 32 bit simulators if you use Swift code in your app.

MOE 2.0 will solve this issue as well (I know, I say this for a lot of things lately :slight_smile: ), because with the LLVM backend we also implemented proper 64 bit support in ART.

Best Regards,
Gergely

Gergely, that’s fantastic! Now, could you just hint me what does it mean to use 32 simulators? Is there a flag or setting I need to specify in XCode or gradle settings or that’s assume only specific devices that could be emulated? I can’t seem to find any settings in XCode (latest version) for selecting simulator kind 64 vs 32bit.

Thanks
Eugene

iPhone 5 and 5C are the last 32bit only iPhone devices, iPad 4th generation is the last 32bit only iPad device. The simulators for these devices and any older devices should be 32bit only.

You can specify in the launch configuration which simulator you want to use.

Best Regards,
Gergely

1 Like

Can’t believe it was that simple! Thank you Gergely!

BTW, there is an unexpected culprit. Apparently I can’t use simulators to make my app screenshots for the Apple app store submission. It doesn’t seem like any of 32-bit simulators are supporting 5.5in and 12.5in screen sizes required for app store listing.

Dear Eugene,

Sounds like you had published your app into Apple Store. Any link ?
I would like to experience a bit the app that built using MOE.

Thanks
Ivan

Not published yet. Still figuring out how to get the app screenshots as per requirements of the Apple’s app store.

i see… hope for your good news :slight_smile:

I think you can capture the screenshot from the emulator.

Gergely, I’ve tried to submit my app to the app store and it got rejected due to a crash on startup. Here is the link to the crash report below, could you please look if this crash is the same issue related to 64-bit simulator?

https://docs.google.com/document/d/1D0ynlbLPBrgyevroXW1_zMxLbSK1WlwZzRvB2SL38jY/edit?usp=sharing

It is weird that you have ~500 frames at the same address before the UIApplicationMain call. Without having access to the source code we can’t really help.