-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[camera] Dispose resources correctly on setDescription #4003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[camera] Dispose resources correctly on setDescription #4003
Conversation
…en cameras, does not recreate _deviceOrientationSubscription each time
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. |
Hi, I was the one that reported the issue. Thank you for fixing on this! Are you sure doing Additionally, what if a camera preview is being displayed and the camera is disposed before the new one is initialised? I don't know this is why I'm asking. |
Yeah thanks again! The fix was exactly what you laid out in your issue report. Those are some good points. There probably should be some future for initializing that can be awaited so we don't accidentally overlap two initialization calls. It does look like _initCalled is never actually used as a future as you point out. I think the CameraController class definitely needs some improvements. Feel free to add to this PR or submit another one, I will also dive into it when I get the chance! |
// dispose resources from previous camera description | ||
if (_initCalled != null) { | ||
await _initCalled; | ||
_unawaited(CameraPlatform.instance.dispose(_cameraId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea that the CameraController
calls dispose
and is still remains usable. This doesn't seem like intended behavior. And now that I look at setDescription
, is it possible to call setDescription
instead of initialize()
to initialize a camera? This also doesn't seem intended.
I think it makes more sense to put this line in setDescription
and not have this conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ill change and test it with that under setDescription.
I agree its weird that you could call setDescription to completely initialize the controller. Since setDescription is really just handling what you used to have to do manually when changing cameras -> re-initialize a controller with a new description. We could throw calls to setDescription if initialize has never been called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I think we should add the _throwIfNotInitialized
method to the top of setDescription
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you going to add _throwIfNotInitialized
to the beginning of the method?
@BradenBagby Are you still planning on updating this PR based on the feedback above? |
Ive moved it to setDescription @bparrishMines . Let me know if you want setDescription to throw an error if its not already initialized instead of just initializing it for you. If thats the case, wouldn't need the dispose call within the if block, but we would probably still want to await _initCalled incase the user is spamming the switch camera button |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a couple more comments.
As a side note, I didn't realize before that setDescription
reinitializes the CameraController
. I don't think the class was designed to be able to handle this, so we are starting to see bugs like this pop up. It may be worth evaluating whether the setDescription
should only be used while recording for the short term. This doesn't block this PR from fixing these bugs though.
Yes I also think it should just be setDescriptionWhileRecording. I should hopefully be able to get to fixing this pr in the next couple days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me except a missing test. Specifically, you could test that dispose is called in setDescription
.
Co-authored-by: Maurice Parrish <[email protected]>
Is this ready for a second review? (It looks like it's failing analysis, but it's not clear to me from discussion above if it's ready for a second look more generally.) |
Update from triage: @bparrishMines will add tests to this when time allows. |
@stuartmorgan I added the tests and also updated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
auto label is removed for flutter/packages/4003, due to This PR has not met approval requirements for merging. You are not a member of flutter-hackers and need 1 more review(s) in order to merge this PR.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
flutter/packages@d0e9a0e...e2ac440 2023-10-01 [email protected] Roll Flutter from d3df8f6 to d42313c (4 revisions) (flutter/packages#5044) 2023-10-01 [email protected] [webview_flutter] Adds app facing implementation to override console log (flutter/packages#4705) 2023-09-30 [email protected] Roll Flutter from 57b5c3c to d3df8f6 (24 revisions) (flutter/packages#5043) 2023-09-30 [email protected] [webview_flutter] Add a method for getting the user agent (flutter/packages#4472) 2023-09-29 [email protected] [webview_flutter_android] Fix race condition in flaky test (flutter/packages#5037) 2023-09-29 [email protected] [ci] Wait for LUCI test checkin in `release` (flutter/packages#4911) 2023-09-29 [email protected] [webview_flutter_android][webview_flutter_wkwebview] Adds support for `getUserAgent` for `webview_flutter` platform implementations (flutter/packages#4927) 2023-09-29 [email protected] [ci] Disable maps tests in Android emulator (flutter/packages#5003) 2023-09-29 [email protected] [camera] Dispose resources correctly on setDescription (flutter/packages#4003) 2023-09-29 [email protected] [webview_flutter_android] Adds Android implementation to override console log (flutter/packages#4702) 2023-09-29 [email protected] [camera] Remove `@throw` from iOS implementation (flutter/packages#5034) 2023-09-29 [email protected] Roll Flutter from ff4a0f6 to 57b5c3c (47 revisions) (flutter/packages#5036) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@d0e9a0e...e2ac440 2023-10-01 [email protected] Roll Flutter from d3df8f6 to d42313c (4 revisions) (flutter/packages#5044) 2023-10-01 [email protected] [webview_flutter] Adds app facing implementation to override console log (flutter/packages#4705) 2023-09-30 [email protected] Roll Flutter from 57b5c3c to d3df8f6 (24 revisions) (flutter/packages#5043) 2023-09-30 [email protected] [webview_flutter] Add a method for getting the user agent (flutter/packages#4472) 2023-09-29 [email protected] [webview_flutter_android] Fix race condition in flaky test (flutter/packages#5037) 2023-09-29 [email protected] [ci] Wait for LUCI test checkin in `release` (flutter/packages#4911) 2023-09-29 [email protected] [webview_flutter_android][webview_flutter_wkwebview] Adds support for `getUserAgent` for `webview_flutter` platform implementations (flutter/packages#4927) 2023-09-29 [email protected] [ci] Disable maps tests in Android emulator (flutter/packages#5003) 2023-09-29 [email protected] [camera] Dispose resources correctly on setDescription (flutter/packages#4003) 2023-09-29 [email protected] [webview_flutter_android] Adds Android implementation to override console log (flutter/packages#4702) 2023-09-29 [email protected] [camera] Remove `@throw` from iOS implementation (flutter/packages#5034) 2023-09-29 [email protected] Roll Flutter from ff4a0f6 to 57b5c3c (47 revisions) (flutter/packages#5036) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
setDescription for CameraController was not correctly handling resources. It would recreate the _deviceOrientationSubscription each time it was called, which caused the subscription to not be disposed correctly. It also was not disposing of the previous device camera
List which issues are fixed by this PR. You must list at least one issue.
Issue seen here: flutter/flutter#126823
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.