mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-30 11:11:53 +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 isCameraOn = ref(false)
|
||||||
const isShowingPreview = ref(false)
|
const isShowingPreview = ref(false)
|
||||||
|
const isInitializingCamera = ref(false)
|
||||||
const originalWidgets = ref<IBaseWidget[]>([])
|
const originalWidgets = ref<IBaseWidget[]>([])
|
||||||
const videoRef = ref<HTMLVideoElement>()
|
const videoRef = ref<HTMLVideoElement>()
|
||||||
const videoContainerRef = ref<HTMLElement>()
|
const videoContainerRef = ref<HTMLElement>()
|
||||||
@@ -553,6 +554,10 @@ async function handleRetake() {
|
|||||||
async function startCameraPreview() {
|
async function startCameraPreview() {
|
||||||
if (props.readonly) return
|
if (props.readonly) return
|
||||||
|
|
||||||
|
// Prevent concurrent camera initialization attempts
|
||||||
|
if (isInitializingCamera.value) return
|
||||||
|
isInitializingCamera.value = true
|
||||||
|
|
||||||
capturedImageUrl.value = null
|
capturedImageUrl.value = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -638,6 +643,8 @@ async function startCameraPreview() {
|
|||||||
|
|
||||||
stopStreamTracks()
|
stopStreamTracks()
|
||||||
isShowingPreview.value = false
|
isShowingPreview.value = false
|
||||||
|
} finally {
|
||||||
|
isInitializingCamera.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user