Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[camera]call engine API in main thread to fix a crash #4661

Merged
merged 5 commits into from
Jan 20, 2022

Conversation

hellohuanlin
Copy link
Contributor

@hellohuanlin hellohuanlin commented Jan 11, 2022

This PR is part of a larger project to fix the thread model for iOS camera plugin. The formal proposal can be found here

The engine APIs used in camera plugin are required to be run on platform thread. Some of these APIs have explicit asserts (e.g. MethodChannel) and some have warning instructions in documentation (e.g. TextureRegistry). However, in camera plugin we are currently calling these APIs in background thread, causing the crash.

There's already a FLTThreadSafeFlutterResult wrapper to invoke FlutterResult in main thread. This PR created similar "thread safe wrappers" for EventChannel, MethodChannel and TextureRegistry.

Issues

flutter/flutter#94723
flutter/flutter#52578

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • [] I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • [] I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@hellohuanlin hellohuanlin marked this pull request as ready for review January 11, 2022 02:02
@hellohuanlin
Copy link
Contributor Author

hellohuanlin commented Jan 11, 2022

Hi @jmagman @cyanglaz and @stuartmorgan, I re-created this PR from last year.

I left comments about what's updated from the last PR. The biggest change is to use completion block which both @cyanglaz and @jmagman suggested.

PTAL again, thank you!

@hellohuanlin hellohuanlin requested review from jmagman, stuartmorgan and cyanglaz and removed request for bparrishMines January 11, 2022 02:05
@hellohuanlin hellohuanlin force-pushed the camera_thread_safe branch 2 times, most recently from 05fa6ba to a0ccf76 Compare January 13, 2022 20:00
Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

LGTM with nits

@hellohuanlin hellohuanlin force-pushed the camera_thread_safe branch 6 times, most recently from c7470b3 to 39a438a Compare January 20, 2022 20:37
@hellohuanlin
Copy link
Contributor Author

FYI I've addressed all nits and will merge in a few hours.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants