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

[camera] Add null check before starting preview #3127

Merged
merged 5 commits into from Oct 21, 2020

Conversation

mvanbeusekom
Copy link
Contributor

@mvanbeusekom mvanbeusekom commented Oct 8, 2020

Description

This pull request adds to the work of @panmari (#2965) and @Gioxxy (#2871) and adds a null reference check to make sure the pictureImageReader is not null before accessing. It also adds additional documentation to the README.md file explaining about managing App lifecycle changes in relation to the camera plugin (required since release 0.5.0 of the plugin).

These changes have been discussed in issue flutter/flutter#19595.

Related Issues

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • 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 signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate a breaking change in CHANGELOG.md and increment major revision).
  • No, this is not a breaking change.

@google-cla
Copy link

google-cla bot commented Oct 8, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Oct 8, 2020
@mvanbeusekom
Copy link
Contributor Author

@googlebot I consent.

@google-cla
Copy link

google-cla bot commented Oct 8, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@panmari
Copy link
Contributor

panmari commented Oct 8, 2020

Awesome, thanks for taking over :)

@panmari
Copy link
Contributor

panmari commented Oct 8, 2020

@googlebot I consent.

@google-cla google-cla bot added cla: yes and removed cla: no labels Oct 8, 2020
@Gioxxy
Copy link

Gioxxy commented Oct 8, 2020

@googlebot I consent.

Copy link
Contributor

@bparrishMines bparrishMines left a comment

Choose a reason for hiding this comment

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

LGTM once tests pass

mvanbeusekom and others added 5 commits October 21, 2020 08:33
Occasionally leads to NullPointerException (potentially due to some race
condition, hard to reproduce deterministically). Example stack trace:

E/AndroidRuntime( 5679): java.lang.NullPointerException: Attempt to
invoke virtual method 'android.view.Surface
android.media.ImageReader.getSurface()' on a null object reference
E/AndroidRuntime( 5679): 	at
io.flutter.plugins.camera.Camera.startPreview(Camera.java:424)
E/AndroidRuntime( 5679): 	at
io.flutter.plugins.camera.Camera$2.onOpened(Camera.java:160)
E/AndroidRuntime( 5679): 	at
android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:145)
E/AndroidRuntime( 5679): 	at
android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime( 5679): 	at
android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime( 5679): 	at
android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime( 5679): 	at
android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime( 5679): 	at
java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 5679): 	at
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime( 5679): 	at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
@amirh
Copy link
Contributor

amirh commented Oct 21, 2020

Landing per @bparrishMines's LGTM

@amirh amirh merged commit 3ac426d into flutter:master Oct 21, 2020
@mvanbeusekom mvanbeusekom deleted the cam_nullptr branch November 2, 2020 09:33
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
Adds a null reference check to make sure the pictureImageReader is not null before accessing. Also adds additional documentation to the README.md file explaining about managing App lifecycle changes in relation to the camera plugin (required since release 0.5.0 of the plugin).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
5 participants