mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 12:52:10 -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() {
|
||||
log.info("=== RENDERING OUTPUT DATA FOR COMFYUI ===");
|
||||
// Check if layers have valid images loaded
|
||||
const layersWithoutImages = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
||||
if (layersWithoutImages.length > 0) {
|
||||
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
|
||||
const stillIncomplete = 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.`);
|
||||
// Check if layers have valid images loaded, with retry logic
|
||||
const maxRetries = 5;
|
||||
const retryDelay = 200;
|
||||
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||
const layersWithoutImages = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
||||
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.`);
|
||||
}
|
||||
}
|
||||
// Użyj zunifikowanych funkcji z CanvasLayers
|
||||
|
||||
@@ -218,17 +218,26 @@ export class CanvasIO {
|
||||
async _renderOutputData(): Promise<{ image: string, mask: string }> {
|
||||
log.info("=== RENDERING OUTPUT DATA FOR COMFYUI ===");
|
||||
|
||||
// Check if layers have valid images loaded
|
||||
const layersWithoutImages = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
||||
if (layersWithoutImages.length > 0) {
|
||||
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 if layers have valid images loaded, with retry logic
|
||||
const maxRetries = 5;
|
||||
const retryDelay = 200;
|
||||
|
||||
// Check again
|
||||
const stillIncomplete = 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.`);
|
||||
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||
const layersWithoutImages = this.canvas.layers.filter(layer => !layer.image || !layer.image.complete);
|
||||
|
||||
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