Fix USB Camera BufferQueue abandoned crash

This commit is contained in:
Jannik committed 2026-08-24 07:26:18 +02:00
1 parent 735642b372
commit b5fd82fe16
11 files changed
+76 -48

No files matched your search

@@ -156,9 +156,25 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
}
} catch (ioe: Exception) {}
// Start the camera preview asynchronously
post {
startPreview()
// Handle SurfaceTexture lifecycle to prevent BufferQueue abandonment
// when the view is obscured (e.g. by PreviewScreen)
textureView.surfaceTextureListener = object : android.view.TextureView.SurfaceTextureListener {
override fun onSurfaceTextureAvailable(surface: android.graphics.SurfaceTexture, width: Int, height: Int) {
startPreview()
}
override fun onSurfaceTextureSizeChanged(surface: android.graphics.SurfaceTexture, width: Int, height: Int) {}
override fun onSurfaceTextureDestroyed(surface: android.graphics.SurfaceTexture): Boolean {
try {
sharedCameraClient?.getCameraStrategy()?.stopPreview()
} catch (e: Exception) {
android.util.Log.e("UsbCameraView", "SurfaceTextureDestroyed err", e)
}
return true
}
override fun onSurfaceTextureUpdated(surface: android.graphics.SurfaceTexture) {}
}
} catch (e: Throwable) {
val errorMsg = "CRASH IN INIT: ${e.message}\n${android.util.Log.getStackTraceString(e)}"