mirror of
https://github.com/Azornes/Comfyui-LayerForge.git
synced 2026-03-21 20:52:12 -03:00
Improve mask loading logic on node connection
Updated mask loading to immediately use available data from connected nodes and preserve existing masks if none is provided. Backend mask data is only fetched after workflow execution, ensuring no stale data is loaded during connection.
This commit is contained in:
@@ -708,10 +708,6 @@ export class CanvasIO {
|
||||
|
||||
// If mask input is disconnected, clear any currently applied mask to ensure full separation
|
||||
if (!hasMaskInput) {
|
||||
if (this.canvas.maskTool) {
|
||||
this.canvas.maskTool.clear();
|
||||
this.canvas.render();
|
||||
}
|
||||
(this.canvas as any).maskAppliedFromInput = false;
|
||||
this.canvas.lastLoadedMaskLinkId = undefined;
|
||||
log.info("Mask input disconnected - cleared mask to enforce separation from input_image");
|
||||
@@ -723,6 +719,12 @@ export class CanvasIO {
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip backend check during mask connection if we didn't get immediate data
|
||||
if (reason === "mask_connect" && !maskLoaded) {
|
||||
log.info("No immediate mask data available during connection, skipping backend check to avoid stale data. Will check after execution.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check backend for input data only if we have connected inputs
|
||||
const response = await fetch(`/layerforge/get_input_data/${nodeId}`);
|
||||
const result = await response.json();
|
||||
|
||||
@@ -796,8 +796,8 @@ export class CanvasRenderer {
|
||||
|
||||
// Position above main canvas but below cursor overlay
|
||||
this.strokeOverlayCanvas.style.position = 'absolute';
|
||||
this.strokeOverlayCanvas.style.left = '1px';
|
||||
this.strokeOverlayCanvas.style.top = '1px';
|
||||
this.strokeOverlayCanvas.style.left = '0px';
|
||||
this.strokeOverlayCanvas.style.top = '0px';
|
||||
this.strokeOverlayCanvas.style.pointerEvents = 'none';
|
||||
this.strokeOverlayCanvas.style.zIndex = '19'; // Below cursor overlay (20)
|
||||
// Opacity is now controlled by MaskTool.previewOpacity
|
||||
|
||||
@@ -1368,12 +1368,18 @@ app.registerExtension({
|
||||
if (index === 1) {
|
||||
if (connected && link_info) {
|
||||
log.info("Input mask connected");
|
||||
|
||||
// DON'T clear existing mask when connecting a new input
|
||||
// Reset the loaded mask link ID to allow loading from the new connection
|
||||
canvas.lastLoadedMaskLinkId = undefined;
|
||||
|
||||
// Mark that we have a pending mask connection
|
||||
canvas.hasPendingMaskConnection = true;
|
||||
// Check for data immediately when connected
|
||||
setTimeout(() => {
|
||||
log.info("Checking for input data after mask connection...");
|
||||
// Only load mask here; images are handled by image connect or execution
|
||||
// Only load mask here if it's immediately available from the connected node
|
||||
// Don't load stale masks from backend storage
|
||||
canvas.canvasIO.checkForInputData({ allowImage: false, allowMask: true, reason: "mask_connect" });
|
||||
}, 500);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user