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

[camera] Fix a disposed CameraController error thrown when changing a camera #4236

Merged
merged 1 commit into from
Aug 13, 2021
Merged

[camera] Fix a disposed CameraController error thrown when changing a camera #4236

merged 1 commit into from
Aug 13, 2021

Conversation

bselwe
Copy link
Contributor

@bselwe bselwe commented Aug 12, 2021

Fixes a disposed CameraController error thrown when changing the camera in the camera example.

The error is thrown by the ValueListenableBuilder in the CameraPreview. Changing a camera disposes the previous CameraController before the widget state is updated causing the ValueListenableBuilder to listen to the disposed controller. This PR solves the issue by disposing the previous CameraController after the new one is initialized.

Error:

The following assertion was thrown building CameraPreview:
A CameraController was used after being disposed.
Once you have called dispose() on a CameraController, it can no longer be
used.

The relevant error-causing widget was:
  CameraPreview
  file:///Users/.../Projects/plugins/packages/camera/camera/example/lib/main.dart:188:16

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. (Note that 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.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

@bselwe
Copy link
Contributor Author

bselwe commented Aug 12, 2021

@ditman @BeMacized @felangel

@ditman
Copy link
Member

ditman commented Aug 12, 2021

The test failure seems like a chrome flake:

UnknownException (13): unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=91.0.4472.101 (af52a90bf87030dd1523486a1cd3ae25c5d76c9b-refs/branch-heads/4472@{#1462}),platform=Linux 5.4.104+ x86_64)

I'll restart the test.

@ditman
Copy link
Member

ditman commented Aug 12, 2021

Hey Bodhi / Maurits, can you take a look at this? Why wasn't this needed earlier? This was discovered while Bart (@bselwe) developed the Web version of the plugin. Thanks!

@BeMacized
Copy link
Contributor

BeMacized commented Aug 13, 2021

Why wasn't this needed earlier?

I'm not entirely sure, but I can reproduce the issue and this does look like the appropriate fix to me.

Copy link
Contributor

@BeMacized BeMacized left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes p: camera waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants