Skip to content

fix(iOS): accelerometer crash when reporting changes - #10893

Closed
ajpinedam wants to merge 1 commit into
unoplatform:masterfrom
ajpinedam:ajpm/feat/ios.accelerometer.crash
Closed

ajpinedam wants to merge 1 commit into
unoplatform:masterfrom
ajpinedam:ajpm/feat/ios.accelerometer.crash

Conversation

@ajpinedam

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #10217

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behaviour?

Application crash when reading Accelerometer values on iOS

What is the new behavior?

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@ajpinedam ajpinedam self-assigned this Jan 5, 2023
@github-actions github-actions Bot added the platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform label Jan 5, 2023
@ajpinedam
ajpinedam marked this pull request as ready for review January 5, 2023 19:08

@MartinZikmund MartinZikmund left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. So I suggest closing this PR and instead adding the Dispatcher.RunAsync to the Gallery app's event handlers

@Youssef1313 Youssef1313 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MartinZikmund Would that apply to

if (CoreDispatcher.Main.HasThreadAccess)
{
CalculateCurrentOrientation(orientation);
}
else
{
_ = CoreDispatcher.Main.RunAsync(CoreDispatcherPriority.Normal, () =>
{
CalculateCurrentOrientation(orientation);
});
}
? UWP Sample

This code is already in main, should it be changed?

@MartinZikmund

MartinZikmund commented Jan 6, 2023 •

Copy link
Copy Markdown
Member

@MartinZikmund Would that apply to

if (CoreDispatcher.Main.HasThreadAccess)
{
CalculateCurrentOrientation(orientation);
}
else
{
_ = CoreDispatcher.Main.RunAsync(CoreDispatcherPriority.Normal, () =>
{
CalculateCurrentOrientation(orientation);
});
}

? UWP Sample
This code is already in main, should it be changed?

Yes indeed, that should be changed to match the other sensors - e.g. trigger on background thread and then the user has to apply Dispatcher themselves.

@MartinZikmund

Copy link
Copy Markdown
Member

As discussed, we need to make sure that the behavior matches WinUI here, so I close this PR for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform/ios 🍎 Categorizes an issue or PR as relevant to the iOS platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants