You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Gallery][iOS]Accelerometer- App crashes when click on ' Start observing Accelerometer reading Changes' Button. #10217
area/canary 🐤Categorizes an issue or PR as relevant to canary testingdifficulty/tbdCategorizes an issue for which the difficulty level needs to be defined.kind/bugSomething isn't workingplatform/ios 🍎Categorizes an issue or PR as relevant to the iOS platform
I somehow got lucky with the Accelerometer on UWP, Android, and WASM and didn't need to use the dispatcher.
After working on the PowerManager (which raises events on background threads on UWP and Android) example I guess this might be the cause of the Accelerometer issue on iOS.
The view model should be changed to raise events on the main thread, something like this:
area/canary 🐤Categorizes an issue or PR as relevant to canary testingdifficulty/tbdCategorizes an issue for which the difficulty level needs to be defined.kind/bugSomething isn't workingplatform/ios 🍎Categorizes an issue or PR as relevant to the iOS platform
Activity
trungnt2910 commentedon Oct 22, 2022
There isn't any platform-specific code in this sample, so this should be a problem in the Uno library itself.ktos commentedon Oct 23, 2022
Just started playing with Magnetometer sample, and the docs both in case of Magnetometer and Accelerometer (https://platform.uno/docs/articles/features/accelerometer.html) are saying that you should use Dispatcher, because updating the sensor's reading and displaying it may occur on two separate threads (and it's behaving the same way on UWP).
The Accelerometer sample is not using Dispatcher: https://github.com/unoplatform/Uno.Gallery/blob/master/Uno.Gallery/Uno.Gallery.UWP/Views/SamplePages/AccelerometerSamplePage.xaml.cs#L178-L181
I believe this crash may be the effect of this.
trungnt2910 commentedon Oct 24, 2022
I somehow got lucky with the
Accelerometeron UWP, Android, and WASM and didn't need to use the dispatcher.After working on the
PowerManager(which raises events on background threads on UWP and Android) example I guess this might be the cause of theAccelerometerissue on iOS.The view model should be changed to raise events on the main thread, something like this:
https://github.com/unoplatform/Uno.Gallery/blob/master/Uno.Gallery/Uno.Gallery.UWP/Views/SamplePages/PowerManagerSamplePage.xaml.cs#L112-L118
I don't have any iOS device so I can't test this fix.
MartinZikmund commentedon Jan 6, 2023
I'm sorry I didn't notice this issue earlier, but it cannot be fixed within Uno, but rather within the Gallery sample. As per the UWP docs and the UWP samples, the event handler should reschedule to Dispatcher thread if needed - https://github.com/microsoft/Windows-universal-samples/blob/ad9a0c4def222aaf044e51f8ee0939911cb58471/Samples/Accelerometer/cs/Scenario1_DataEvents.xaml.cs#L86 . The reason is that for high-throughput scenarios where you want to just process accelerometer events as they come, you definitely prefer to be on the background thread. This way the Dispatcher would get swamped with potentially hundreds of events and the app would start freezing.