Bug 44709 - [watchOS] CMDeviceMotion properties aren't all populated with data/cause crash
Summary: [watchOS] CMDeviceMotion properties aren't all populated with data/cause crash
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.WatchOS.dll ()
Version: XI 10.0 (iOS10)
Hardware: PC Mac OS
: --- normal
Target Milestone: (C9)
Assignee: Ivan Herrera
Depends on:
Reported: 2016-09-24 04:12 UTC by CraigD
Modified: 2017-01-11 11:14 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

sample Xamarin watchOS project demonstrating issue (130.38 KB, application/zip)
2016-09-24 04:12 UTC, CraigD

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description CraigD 2016-09-24 04:12:03 UTC
Created attachment 17725 [details]
sample Xamarin watchOS project demonstrating issue

TL;DR not sure if there is a binding problem with three properties on CMDeviceMotion:Gravity, UserAcceleration, MagneticField. Testing on iPhone 7Plus, Watch Series 1, watchOS 3, Xamarin stable, Xcode 8


The attached Xamarin watchOS project is an attempted port of:

Summary of code:

CMMotionManager motionManager = new CMMotionManager();
motionManager.DeviceMotionUpdateInterval = sampleInterval;
motionManager.StartDeviceMotionUpdates(queue, (deviceMotion, error) =>
//   Console.WriteLine(deviceMotion.Gravity);            // CRASHES
//   Console.WriteLine(deviceMotion.UserAcceleration);   // CRASHES
//   Console.WriteLine(deviceMotion.MagneticField);      // CRASHES

The `deviceMotion`, `Attitude` and `MagneticField` are all valid objects that work as expected (output example shown below).

BUT the other properties (Gravity, UserAcceleration, MagneticField) cause the app to crash immediately if any of them are referenced (they're structs, so I can't do a null check), and the crash occurs even if wrapped in try{}catch{} block.

Example output of the working properties (streams as device is moved):

deviceMotion>QuaternionX 0.069977 QuaternionY - 0.273441 QuaternionZ 0.580755 QuaternionW - 0.763582 UserAccelX - 0.343605 UserAccelY - 0.612576 UserAccelZ - 0.128299 RotationRateX 0.010139 RotationRateY - 0.001787 RotationRateZ - 0.010357 MagneticFieldX 0.000000 MagneticFieldY 0.000000 MagneticFieldZ 0.000000 MagneticFieldAccuracy - 1 @ 79268.313185
deviceMotion.Attitude>Pitch: -25.117162, Roll: 21.804014, Yaw: -69.597130

NOTE: to use the sample app attached, once it starts Force Touch to show the Start button.
NOTE2: the Swift example runs fine on my hardware.
Comment 1 Vincent Dondain [MSFT] 2016-09-29 18:39:25 UTC
@rolf could confirm this bug porfavor? I do not currently have a watchOS 3 device and the test case is full of watchOS 3 only APIs.

The bug report looks very complete though thanks Craig.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2016-10-03 13:07:40 UTC
I can reproduce.