mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-28 18:54:09 +00:00
fix: prevent race condition in camera initialization
- Add isInitializingCamera flag to prevent concurrent calls to startCameraPreview - Use finally block to ensure flag is always reset after initialization
This commit is contained in:
@@ -95,6 +95,7 @@ const props = defineProps<{
|
||||
|
||||
const isCameraOn = ref(false)
|
||||
const isShowingPreview = ref(false)
|
||||
const isInitializingCamera = ref(false)
|
||||
const originalWidgets = ref<IBaseWidget[]>([])
|
||||
const videoRef = ref<HTMLVideoElement>()
|
||||
const videoContainerRef = ref<HTMLElement>()
|
||||
@@ -553,6 +554,10 @@ async function handleRetake() {
|
||||
async function startCameraPreview() {
|
||||
if (props.readonly) return
|
||||
|
||||
// Prevent concurrent camera initialization attempts
|
||||
if (isInitializingCamera.value) return
|
||||
isInitializingCamera.value = true
|
||||
|
||||
capturedImageUrl.value = null
|
||||
|
||||
try {
|
||||
@@ -638,6 +643,8 @@ async function startCameraPreview() {
|
||||
|
||||
stopStreamTracks()
|
||||
isShowingPreview.value = false
|
||||
} finally {
|
||||
isInitializingCamera.value = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user