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() {
|
||||
captureSession?.close()
|
||||
try {
|
||||
captureSession?.stopRepeating()
|
||||
captureSession?.abortCaptures()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
try {
|
||||
captureSession?.close()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
captureSession = null
|
||||
imageReader?.close()
|
||||
|
||||
try {
|
||||
imageReader?.close()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
imageReader = null
|
||||
cameraDevice?.close()
|
||||
|
||||
try {
|
||||
cameraDevice?.close()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
cameraDevice = null
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user