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

Conversation

@hellohuanlin
Copy link
Contributor

@hellohuanlin hellohuanlin commented Aug 23, 2022

Why this bug?

introduced in flutter/flutter#109910

This is the same reason why we can't use weakSelf in FLTThreadSafeFlutterResult - it's only retained within a call stack, not in the heap. So when dispatched back to main, the wrapper has been gone.

Workaround

As a temp workaround, I will simply revert the change in FLTThreadSafeEventChannel to fix the bug. An alternative workaround is to make FLTThreadSafeEventChannel an ivar and keep it around during streaming. I have verified that both works.

In this particular example, we don't have to worry about strongSelf making engine API being called after engine is torn down. This is because engine would have to be dispatched to the main thread to be torn down, which must happen after the current block that we just enqueued.

Long term solution

However, I dislike this approach, because all our thread safe wrappers cannot be re-used as general utilitys - they can only be used in this particular context of camera plugin.

In the long term, I think a more general solution is to always use strong reference to the wrapper itself (where the retain cycle will be broken after the work is done dispatching), but pass in weak reference of the plugin, and use the plugin reference to tell if the engine is torn down or not (instead of using wrapper reference). This approach will make the wrapper working for both ivar and local variable/argument scenarios, while still avoiding calling engine API after engine is torn down.

List which issues are fixed by this PR. You must list at least one issue.

Fixes flutter/flutter#109910

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 flxtter/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 August 23, 2022 04:36
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@jmagman
Copy link
Member

jmagman commented Aug 23, 2022

@hellohuanlin
Copy link
Contributor Author

@jmagman oh I initially pushed without tests. test was added later. so we should be good

@jmagman
Copy link
Member

jmagman commented Aug 23, 2022

@jmagman oh I initially pushed without tests. test was added later. so we should be good

Oh okay good, thanks!

XCTestExpectation *expectation =
[self expectationWithDescription:@"Completion should be called."];
dispatch_async(dispatch_queue_create("test", NULL), ^{
FLTThreadSafeEventChannel *channel = [[FLTThreadSafeEventChannel alloc]
Copy link
Member

Choose a reason for hiding this comment

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

@autoreleasepool to release it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need because the channel defined within the scope of the dispatch_async.

I tested it out and this test fails the previous code and passes the current code. So we should be fine.

Copy link
Member

@jmagman jmagman left a comment

Choose a reason for hiding this comment

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

LGTM

@hellohuanlin hellohuanlin added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 23, 2022
@auto-submit auto-submit bot merged commit e4cabdf into flutter:main Aug 23, 2022
moisefeelin pushed a commit to feelinproject/plugins that referenced this pull request Aug 26, 2022
mauricioluz pushed a commit to mauricioluz/plugins that referenced this pull request Jan 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-ios

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[camera] startImageStream throws MissingPluginException and callback is not called

2 participants