Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Surface had no valid native window. on barcodeView.start() #13

Closed
OmarJoya opened this issue Apr 29, 2019 · 7 comments
Closed

Surface had no valid native window. on barcodeView.start() #13

OmarJoya opened this issue Apr 29, 2019 · 7 comments
Labels
bug Something isn't working

Comments

@OmarJoya
Copy link

OmarJoya commented Apr 29, 2019

Once I grant the CAMERA permissions barcodeView.start() throws an error

On Android Marshmallow is not needed call to start but on Android Pie

I want to know if there is a way to know if the barcode is already started to avoid calling .start()

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.centinal.ivs.internal.debug, PID: 17159
java.lang.IllegalArgumentException: Surface was abandoned
at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:70)
at android.hardware.camera2.params.OutputConfiguration.(OutputConfiguration.java:97)
at android.hardware.camera2.params.OutputConfiguration.(OutputConfiguration.java:71)
at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:474)
at uk.co.brightec.kbarcode.camera.Camera2Source.createCaptureSession$kbarcode_release(Camera2Source.kt:121)
at uk.co.brightec.kbarcode.camera.Camera2Source$start$1.onOpened(Camera2Source.kt:55)
at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:134)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: android.hardware.camera2.legacy.LegacyExceptionUtils$BufferQueueAbandonedException
at android.hardware.camera2.legacy.LegacyExceptionUtils.throwOnError(LegacyExceptionUtils.java:64)
at android.hardware.camera2.legacy.LegacyCameraDevice.getSurfaceSize(LegacyCameraDevice.java:540)
at android.hardware.camera2.utils.SurfaceUtils.getSurfaceSize(SurfaceUtils.java:68)
at android.hardware.camera2.params.OutputConfiguration.(OutputConfiguration.java:97) 
at android.hardware.camera2.params.OutputConfiguration.(OutputConfiguration.java:71) 
at android.hardware.camera2.impl.CameraDeviceImpl.createCaptureSession(CameraDeviceImpl.java:474) 
at uk.co.brightec.kbarcode.camera.Camera2Source.createCaptureSession$kbarcode_release(Camera2Source.kt:121) 
at uk.co.brightec.kbarcode.camera.Camera2Source$start$1.onOpened(Camera2Source.kt:55) 
at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:134) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

@OmarJoya OmarJoya added the bug Something isn't working label Apr 29, 2019
@OmarJoya OmarJoya changed the title Surface had no valid native window. on barcodeView.tart() Surface had no valid native window. on barcodeView.start() Apr 29, 2019
@alistairsykes

This comment has been minimized.

@alistairsykes alistairsykes self-assigned this May 8, 2019
@OmarJoya
Copy link
Author

OmarJoya commented May 8, 2019

Yes, also I added the BarcodeView as an observer to the lifecycle in onActivityCreated as you have on https://github.com/brightec/KBarcode/wiki

image

@alistairsykes
Copy link
Contributor

This exception does appear to be caused by affectively calling barcodeView.start() twice, in quick succession.

I had previously thought the library handled calling start() twice, as seen in BarcodeScanner.start() where I check if the cameraSource.isStarted(). However if you call twice in quick succession, the second time the camera source does not report as starting because it is still opening the camera.

I will create a pull request soon which will address this issue.

For your case @OmarJoya, you are right that marshmallow is the differing factor. It appears that permissions dialogs behave differently between M and Q (not sure exactly for each version in between). On M the permissions dialog causes @OnLifecycleEvent(Lifecycle.Event.ON_START) to be called when it dismisses. On Q it does not.
A temporary work around while I get this pull request together, would be to do a version check before calling barcodeView.start() after the permission is granted.

alistairsykes added a commit that referenced this issue May 8, 2019
…nables us to check and not start the camera again if it is currently opening. Added tests which check the new behavioural changes.
NickHolcombe added a commit that referenced this issue May 9, 2019
@alistairsykes
Copy link
Contributor

Pull request has been approved and merged.

@OmarJoya
Copy link
Author

OmarJoya commented May 9, 2019

does this last merge contain the fix?, I'm now using the kbarcode version 1.0.2, but seems the problem is not solved

@alistairsykes
Copy link
Contributor

We are yet to do a release with this fix in. We had a few other things to get done before publishing the code. I will post again on this issue once we have done that.

@alistairsykes
Copy link
Contributor

We have now done a release which includes this fix.

https://github.com/brightec/KBarcode/releases/tag/v1.0.3

@alistairsykes alistairsykes removed their assignment May 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants