Open unipheye opened 7 years ago
Hi @unipheye , any update on this? having the same issue here :(
Hi @AugustoL, I haven't found a solution yet. Though I have a app where this issue doesn't seem to occur. I am going to take a deep dive today. I will post all findings later.
This issue doesn't seem to be the same issue as #47 "pop to the Previous scene in android 4.x black scene in screen"
Small update:
I have figured out where the "Camera is being used after Camera.release() was called" came from. In the source of react-native-barcodescanner, when the device goes into sleep mode, two functions are being called after the camera is already released: "stopCameraPreview()" and "mCameraManager.releaseCamera()". This triggered the error. Just to get the error away I have made the following modifications to the source.
Add a global variable
private boolean mReleased = false;
Alter stopCamera function
public void stopCamera() {
if(!mReleased){
stopCameraPreview();
mCameraManager.releaseCamera();
mReleased = true;
}
}
Modify startCameraPreview() by adding the following line between the try block
mReleased = false;
Unfortunately this does not solve the issue with the black screen. It somehow seems as if the preview cannot be started after the device when into sleep mode. In the android device monitor I get the following error:
SprdCameraHardware(177) void android::SprdCameraHardware::receivePreviewFrame(camera_frame_type*): displayOneFrame not successful!
I can't find anything sensible about this error. So I am currently stuck at finding a solution ...
Hi!
I have fixed this and made a pr here: https://github.com/ideacreation/react-native-barcodescanner/pull/59
The issue is that this library does not handle multiple camera instances properly, and react's handling of the module instances shouldn't really be depended on. So, all I did was make the camera static.
Hi @getreup,
Thanks for responding to this issue but unfortunately I still get a black screen and the same error:
SprdCameraHardware(177) void android::SprdCameraHardware::receivePreviewFrame(camera_frame_type*): displayOneFrame not successful!
But you did experience the same issues and now they are gone? Could you give me some more info on that?
Thanks
Hi @unipheye
I found that the mCamera instance was being created multiple times. If you put a break point at new Camera(), then you might see the same. The issue happens when the second instance is being used instead of the first. So, I figured making it static would be an easy hack to get this going, especially since the library doesn't handle multiple instances of mCamera anyways, so it kinda makes sense.
Hi @getreup ! making mCamera static didn't help me. if you have any other ideas - please post them. thanks in advance! Android 4.4.2 RN 0.34.1 Scanner 3.1.1
@bo4a10 Hey can you try debugging and seeing if there are multiple instances of "new Camera()" being created? That would be my best advice.
Hi @getreup I have tried your method, but it also doesn't work for me. If you have any progress I will try again. This performance bug makes me very despaired.
That sucks ... the only thing I did is in the PR. But I would just suggest throwing breakpoints wherever "new Camera()" is being called and make sure you're never really recreating it twice.
I experienced this issue on my Meizu MX5, fixed it by making CameraManager a singleton. Please check whether pr #61 solved your problem @bo4a10
@jiaminglu thanks.
Hi @jiaminglu! Yes, your PR fixed problem as for me. Nice work. Thank you!
hi @jiaminglu ,thank you! Issue has fixed. However, i have another performace problem. When i exit the app and open it again each view runs not smoothly. But when i go to the view which uses the camera, besides first open this view is not smoothly, the app runs smoothly everywhere.
@jiaminglu it works, thank you!
@jiaminglu it really works. This bug was a real thorn in my side. Thank you!
@jiaminglu Thank you, that totally worked!
@jiaminglu Thank you very much! You are wonderful 👍
Hi,
The camera doesn't wake up / work after the device has been in sleep mode or the screen was in screen timeout mode.
Test Device
How to replicate the issue:
In all of my apps the viewfinder is black after walking through the previous steps
What I found so far:
09-01 22:56:55.833: E/CameraPreview(15121): java.lang.RuntimeException: Camera is being used after Camera.release() was called 09-01 22:56:55.833: E/CameraPreview(15121): java.lang.RuntimeException: Camera is being used after Camera.release() was called 09-01 22:56:55.833: E/CameraPreview(15121): at android.hardware.Camera.native_cancelAutoFocus(Native Method) 09-01 22:56:55.833: E/CameraPreview(15121): at android.hardware.Camera.cancelAutoFocus(Camera.java:1348) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.CameraPreview.stopCameraPreview(CameraPreview.java:89) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.CameraPreview.stopCamera(CameraPreview.java:52) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.BarcodeScannerView.onPause(BarcodeScannerView.java:43) 09-01 22:56:55.833: E/CameraPreview(15121): at com.eguma.barcodescanner.BarcodeScannerManager.onHostPause(BarcodeScannerManager.java:58) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.bridge.ReactContext.onHostPause(ReactContext.java:179) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.XReactInstanceManagerImpl.moveToBeforeResumeLifecycleState(XReactInstanceManagerImpl.java:573) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.XReactInstanceManagerImpl.onHostPause(XReactInstanceManagerImpl.java:489) 09-01 22:56:55.833: E/CameraPreview(15121): at com.facebook.react.ReactActivity.onPause(ReactActivity.java:120) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.Activity.performPause(Activity.java:6765) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1338) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4418) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.performPauseActivity(ActivityThread.java:4391) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:4366) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.access$1200(ActivityThread.java:219) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1746) 09-01 22:56:55.833: E/CameraPreview(15121): at android.os.Handler.dispatchMessage(Handler.java:102) 09-01 22:56:55.833: E/CameraPreview(15121): at android.os.Looper.loop(Looper.java:145) 09-01 22:56:55.833: E/CameraPreview(15121): at android.app.ActivityThread.main(ActivityThread.java:6939) 09-01 22:56:55.833: E/CameraPreview(15121): at java.lang.reflect.Method.invoke(Native Method) 09-01 22:56:55.833: E/CameraPreview(15121): at java.lang.reflect.Method.invoke(Method.java:372) 09-01 22:56:55.833: E/CameraPreview(15121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 09-01 22:56:55.833: E/CameraPreview(15121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Please help! I really need this to work.
Thanks.
Regards, Gawein