fix(android): Fix Android Camera1 race condition crash (#2781)
* add synchronized to take pictures callback in case camera was already stopped. This will also prevent a possible null camera object. * use our mCamera variable instead of the one received in the callback so we know if it has been disposed. Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
This commit is contained in:
parent
bfe04aaec8
commit
85b951ced1
@ -760,16 +760,23 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
|
||||
sound.play(MediaActionSound.SHUTTER_CLICK);
|
||||
}
|
||||
|
||||
if (options.hasKey("pauseAfterCapture") && !options.getBoolean("pauseAfterCapture")) {
|
||||
camera.startPreview();
|
||||
mIsPreviewActive = true;
|
||||
if (mIsScanning) {
|
||||
camera.setPreviewCallback(Camera1.this);
|
||||
// our camera might have been released
|
||||
// when this callback fires, so make sure we have
|
||||
// exclusive access when restoring its preview
|
||||
synchronized(Camera1.this){
|
||||
if(mCamera != null){
|
||||
if (options.hasKey("pauseAfterCapture") && !options.getBoolean("pauseAfterCapture")) {
|
||||
mCamera.startPreview();
|
||||
mIsPreviewActive = true;
|
||||
if (mIsScanning) {
|
||||
mCamera.setPreviewCallback(Camera1.this);
|
||||
}
|
||||
} else {
|
||||
mCamera.stopPreview();
|
||||
mIsPreviewActive = false;
|
||||
mCamera.setPreviewCallback(null);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
camera.stopPreview();
|
||||
mIsPreviewActive = false;
|
||||
camera.setPreviewCallback(null);
|
||||
}
|
||||
|
||||
isPictureCaptureInProgress.set(false);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user