mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 20:52:12 -03:00
Add retry logic for image loading validation
Increase robustness of image loading check before sending canvas data. Now retries up to 5 times with 200ms delays (1 second total) instead of a single 100ms wait. This fixes the 'Failed to get confirmation from server' error that appeared when executing workflows immediately after ComfyUI restart, before images finished loading from IndexedDB. Prevents workflow execution failures due to timing issues during canvas initialization.
This commit is contained in:
@@ -197,16 +197,23 @@ export class CanvasIO {
|
|||||||
}
|
}
|
||||||
async _renderOutputData() {
|
async _renderOutputData() {
|
||||||
log.info("=== RENDERING OUTPUT DATA FOR COMFYUI ===");
|
log.info("=== RENDERING OUTPUT DATA FOR COMFYUI ===");
|
||||||
// Check if layers have valid images loaded
|
// Check if layers have valid images loaded, with retry logic
|
||||||
const layersWithoutImages = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
const maxRetries = 5;
|
||||||
if (layersWithoutImages.length > 0) {
|
const retryDelay = 200;
|
||||||
log.warn(`${layersWithoutImages.length} layer(s) have incomplete image data. Waiting for images to load...`);
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||||
// Wait a bit for images to load
|
const layersWithoutImages = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
if (layersWithoutImages.length === 0) {
|
||||||
// Check again
|
break; // All images loaded
|
||||||
const stillIncomplete = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
}
|
||||||
if (stillIncomplete.length > 0) {
|
if (attempt === 0) {
|
||||||
throw new Error(`Canvas not ready: ${stillIncomplete.length} layer(s) still have incomplete image data. Try clicking on a layer to force initialization, or wait a moment and try again.`);
|
log.warn(`${layersWithoutImages.length} layer(s) have incomplete image data. Waiting for images to load...`);
|
||||||
|
}
|
||||||
|
if (attempt < maxRetries - 1) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Last attempt failed
|
||||||
|
throw new Error(`Canvas not ready after ${maxRetries} attempts: ${layersWithoutImages.length} layer(s) still have incomplete image data. Try waiting a moment and running again.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Użyj zunifikowanych funkcji z CanvasLayers
|
// Użyj zunifikowanych funkcji z CanvasLayers
|
||||||
|
|||||||
@@ -218,17 +218,26 @@ export class CanvasIO {
|
|||||||
async _renderOutputData(): Promise<{ image: string, mask: string }> {
|
async _renderOutputData(): Promise<{ image: string, mask: string }> {
|
||||||
log.info("=== RENDERING OUTPUT DATA FOR COMFYUI ===");
|
log.info("=== RENDERING OUTPUT DATA FOR COMFYUI ===");
|
||||||
|
|
||||||
// Check if layers have valid images loaded
|
// Check if layers have valid images loaded, with retry logic
|
||||||
const layersWithoutImages = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
const maxRetries = 5;
|
||||||
if (layersWithoutImages.length > 0) {
|
const retryDelay = 200;
|
||||||
log.warn(`${layersWithoutImages.length} layer(s) have incomplete image data. Waiting for images to load...`);
|
|
||||||
// Wait a bit for images to load
|
|
||||||
await new Promise(resolve => setTimeout(resolve, 100));
|
|
||||||
|
|
||||||
// Check again
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||||
const stillIncomplete = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
const layersWithoutImages = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
||||||
if (stillIncomplete.length > 0) {
|
|
||||||
throw new Error(`Canvas not ready: ${stillIncomplete.length} layer(s) still have incomplete image data. Try clicking on a layer to force initialization, or wait a moment and try again.`);
|
if (layersWithoutImages.length === 0) {
|
||||||
|
break; // All images loaded
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attempt === 0) {
|
||||||
|
log.warn(`${layersWithoutImages.length} layer(s) have incomplete image data. Waiting for images to load...`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (attempt < maxRetries - 1) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
||||||
|
} else {
|
||||||
|
// Last attempt failed
|
||||||
|
throw new Error(`Canvas not ready after ${maxRetries} attempts: ${layersWithoutImages.length} layer(s) still have incomplete image data. Try waiting a moment and running again.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user