You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Confirming this diagnosis from a separate investigation — setCamera(null, -1) from CameraActivity.onPause() being swallowed by the if (camera != null) guard leaves Preview.mCamera pointing at a released Camera, and it crashes on the next configuration change:
FATAL EXCEPTION: main
java.lang.RuntimeException: Camera is being used after Camera.release() was called
at android.hardware.Camera.setDisplayOrientation(Native Method)
at com.ahm.capacitor.camera.preview.Preview.setCameraDisplayOrientation(Preview.java:145)
at com.ahm.capacitor.camera.preview.CameraActivity.onConfigurationChanged(CameraActivity.java:423)
One thing worth flagging before this lands: I built 8.0.1 with only this change applied and the same steps still crash, because setCameraDisplayOrientation() dereferences mCamera unconditionally and is reachable from onConfigurationChanged() while the activity is paused. Clearing the field changes the exception type rather than removing the crash:
FATAL EXCEPTION: main
java.lang.NullPointerException: Attempt to invoke virtual method
'void android.hardware.Camera.setDisplayOrientation(int)' on a null object reference
at com.ahm.capacitor.camera.preview.Preview.setCameraDisplayOrientation(Preview.java:146)
at com.ahm.capacitor.camera.preview.CameraActivity.onConfigurationChanged(CameraActivity.java:423)
(Reproduced on a Redmi Note 8 / Android 13: open the preview, background the app, rotate while backgrounded, return, leave the screen.)
So this needs an mCamera == null early return in setCameraDisplayOrientation() alongside it. I've opened #423 which carries that guard plus a separate fix for an IllegalStateException in stop(); it includes an equivalent of this change so it stands alone, but I'd be glad to rebase it onto this PR if you'd rather merge yours first — the diagnosis here was first.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
setCameragets called withnullwhen camera is released. Caused some crashes because it didn't propagate toPreview