RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.81k stars 405 forks source link

Can't start preview because of the exception: java.io.IOException: setPreviewTexture failed #295

Open marekfoltyn opened 5 years ago

marekfoltyn commented 5 years ago

Sometimes (about 1 of 15 attempts) preview won't start, because of the following exception:

D/Fotoapparat: Can't start preview because of the exception: java.io.IOException: setPreviewTexture failed

It happens usually when the device is being rotated (the Activity gets recreated) on both my devices (Samsung Galaxy S5 and Samsung Galaxy Tab S2).

EDIT: just found the same issue in #178, but it appears not fixed, the exception is just ignored.

Thank you for tips how to solve this.

fb89 commented 5 years ago

I think, it happens because Texture may not be available yet (it became destroyed once you rotate your device). So onSurfaceTextureAvailable/onSurfaceTextureDestroyed methods must be used for saving actual Texture state here io.fotoapparat.view.CameraView

marekfoltyn commented 5 years ago

Thanks for your advice. If I understand it correctly, you think that I should initialize Fotoapparat instance in cameraView.onSurfaceTextureAvailable method?

EDIT: Since io.fotoapparat.CameraView inherits from FrameLayout and the SurfaceTexture view is a private member, I am not able to set a callback to this view. However, this should be in responsibility of the Fotoapparat library, shouldn't it?