Skip to content

[Gallery][iOS]Accelerometer- App crashes when click on ' Start observing Accelerometer reading Changes' Button. #10217

Closed
unoplatform/Uno.Gallery
#607

Description

@sakshi173

Current behavior

Accelormeter_iOS.MOV

Expected behavior

Gallery app should not crash.

How to reproduce it (as minimally and precisely as possible)

  1. Open Uno Gallery APP
  2. Tap Burger Menu on the left top right.
  3. Tap "Accelerometer" from the "Non-UI Features" list.
  4. Add some time duration in the 'Report Interval' section.
  5. Click the 'Start observing Accelerometer reading Changes' button.
  6. Update the time duration by clicking on the top or down arrow buttons on the Report Interval drop-down.
  7. Notice that after a few seconds the Gallery app gets crashes.

Workaround

No response

Works on UWP/WinUI

No response

Environment

No response

NuGet package version(s)

No response

Affected platforms

iOS

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

Activity

  1. added
    kind/bug
    platform/ios 🍎
    triage/untriaged
    area/canary 🐤
    difficulty/tbd
    on Oct 21, 2022
  2. trungnt2910 commented on Oct 22, 2022

    @trungnt2910
    Contributor

    There isn't any platform-specific code in this sample, so this should be a problem in the Uno library itself.

  3. ktos commented on Oct 23, 2022

    @ktos

    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.

    GitHub
    The Uno Platform Gallery application. Contribute to unoplatform/Uno.Gallery development by creating an account on GitHub.
  4. trungnt2910 commented on Oct 24, 2022

    @trungnt2910
    Contributor

    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:

    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.

    GitHub
    The Uno Platform Gallery application. Contribute to unoplatform/Uno.Gallery development by creating an account on GitHub.
  5. removed
    triage/untriaged
    on Dec 2, 2022
  6. self-assigned this
    on Dec 20, 2022
  7. MartinZikmund commented on Jan 6, 2023

    @MartinZikmund
    Member

    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.

    GitHub
    API samples for the Universal Windows Platform. Contribute to microsoft/Windows-universal-samples development by creating an account on GitHub.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/canary 🐤difficulty/tbdkind/bugplatform/ios 🍎

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions