refactor: 改进 CameraHelper 资源清理的错误处理
- 添加 stopRepeating() 和 abortCaptures() 调用 - 为每个资源关闭操作添加独立的 try-catch - 确保即使部分资源关闭失败,其他资源仍会被清理 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -149,11 +149,32 @@ class CameraHelper(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun closeCamera() {
|
private fun closeCamera() {
|
||||||
|
try {
|
||||||
|
captureSession?.stopRepeating()
|
||||||
|
captureSession?.abortCaptures()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
captureSession?.close()
|
captureSession?.close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
captureSession = null
|
captureSession = null
|
||||||
|
|
||||||
|
try {
|
||||||
imageReader?.close()
|
imageReader?.close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
imageReader = null
|
imageReader = null
|
||||||
|
|
||||||
|
try {
|
||||||
cameraDevice?.close()
|
cameraDevice?.close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
cameraDevice = null
|
cameraDevice = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user