App crashes with com.apple.CoreMotion.MotionThread (29): shared-library-event (18)

When my app tries to start CMMotionManager, it crashes with 'ahpl_main (30): EXC_BAD_ACCESS (code=1, address=0x4230)' error.

It's not always, but sometimes like when I tries to start CMMotionManager right after app is launched.

motionManager = CMMotionManager()

motionManager?.deviceMotionUpdateInterval = 1.0

guard motionManager.isDeviceMotionAvailable else { return }

motionManager?.startDeviceMotionUpdates(to: OperationQueue.current!, withHandler: { [weak self] (motion, error) in
})

This might be a memory issue..?

If I need to provide more information, I am happy to do so.

Thank you for your help.

We also experience many unexplained crashes in CoreMotion.

Crashed: com.apple.CoreMotion.MotionThread
0  CoreMotion                     0x48a0 CLMotionActivity::isTypeIndoorPedestrian(CLMotionActivity::Type) + 1944
1  CoreMotion                     0x3814 CLMotionActivity::isTypeRunning(CLMotionActivity::Type) + 3884
2  CoreMotion                     0x1bf8 (Missing UUID 03f246e3bedf3b11a8c483a389b032ff)
3  IOKit                          0x3da0 __IOHIDEventSystemClientQueueCallback + 280
4  CoreFoundation                 0xa69c __CFMachPortPerform + 172
5  CoreFoundation                 0x4a4ec __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
6  CoreFoundation                 0x4dadc __CFRunLoopDoSource1 + 588
7  CoreFoundation                 0xb0f0 __CFRunLoopRun + 2376
8  CoreFoundation                 0x1de1c CFRunLoopRunSpecific + 572
9  CoreFoundation                 0x98300 CFRunLoopRun + 60
10 CoreMotion                     0x121d4 CLMotionActivity::isTypeInVehicle(CLMotionActivity::Type) + 21412
11 libsystem_pthread.dylib        0x63a4 _pthread_start + 116
12 libsystem_pthread.dylib        0x49fc thread_start + 8

We are also experiencing this crash and we can't find the reason for it. Any clue on what is the trigger?

Bump.

Same problem in a Task wrapping URLSession.shared.data(from:).

I tried giving it .background priority as the doc for Task.result hinted.

Task.checkCancelled() at various points, no effect.

Using URLRequest, no effect.

PlaygroundPage.current.needsIndefiniteExecution = true, no effect.

Importing Foundation, UIKit, or AppKit made no difference, which is kind of crazy, a UIKit playground ought to say it can't find AppKit.

The Playground console says:

error: execution stopped with unexpected state.
error: Execution was interrupted, reason: shared-library-event.

Not informative so far in my searches.

App crashes with com.apple.CoreMotion.MotionThread (29): shared-library-event (18)
 
 
Q