-
Notifications
You must be signed in to change notification settings - Fork 378
fix mask editor bug under vueNodes #5953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,7 @@ import { computed, ref, watch } from 'vue' | |
import { useI18n } from 'vue-i18n' | ||
|
||
import { downloadFile } from '@/base/common/downloadUtil' | ||
import { app } from '@/scripts/app' | ||
import { useCommandStore } from '@/stores/commandStore' | ||
import { useNodeOutputStore } from '@/stores/imagePreviewStore' | ||
|
||
|
@@ -186,8 +187,30 @@ const handleImageError = () => { | |
actualDimensions.value = null | ||
} | ||
|
||
const handleEditMask = () => { | ||
void commandStore.execute('Comfy.MaskEditor.OpenMaskEditor') | ||
const handleEditMask = async () => { | ||
if (props.nodeId) { | ||
const node = app.rootGraph?.getNodeById(props.nodeId) | ||
if (node) { | ||
node.imageIndex = currentIndex.value | ||
|
||
node.imgs = await Promise.all( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [quality] medium Priority Issue: Promise rejection not handled - Image loading could fail silently There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [performance] medium Priority Issue: Blocking image loading may freeze UI |
||
props.imageUrls.map((url) => { | ||
return new Promise<HTMLImageElement>((resolve) => { | ||
const img = new Image() | ||
|
||
img.crossOrigin = 'anonymous' | ||
christian-byrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
img.onload = () => resolve(img) | ||
|
||
img.src = url | ||
}) | ||
}) | ||
) | ||
|
||
app.canvas?.selectNode(node) | ||
} | ||
} | ||
|
||
await commandStore.execute('Comfy.MaskEditor.OpenMaskEditor') | ||
} | ||
|
||
const handleDownload = () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,11 +379,15 @@ export class ComfyApp { | |
const paintedIndex = selectedIndex + 1 | ||
const combinedIndex = selectedIndex + 2 | ||
|
||
// for vueNodes mode | ||
const images = | ||
node.images ?? useNodeOutputStore().getNodeOutputs(node)?.images | ||
|
||
ComfyApp.clipspace = { | ||
widgets: widgets, | ||
imgs: imgs, | ||
original_imgs: orig_imgs, | ||
images: node.images, | ||
images: images, | ||
selectedIndex: selectedIndex, | ||
img_paste_mode: 'selected', // reset to default im_paste_mode state on copy action | ||
paintedIndex: paintedIndex, | ||
|
@@ -410,7 +414,8 @@ export class ComfyApp { | |
ComfyApp.clipspace.imgs[ComfyApp.clipspace.combinedIndex].src | ||
} | ||
if (ComfyApp.clipspace.imgs && node.imgs) { | ||
if (node.images && ComfyApp.clipspace.images) { | ||
// Update node.images even if it's initially undefined (vueNodes mode) | ||
if (ComfyApp.clipspace.images) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [quality] high Priority Issue: Logic condition removed may cause null reference errors |
||
if (ComfyApp.clipspace['img_paste_mode'] == 'selected') { | ||
node.images = [ | ||
ComfyApp.clipspace.images[ComfyApp.clipspace['selectedIndex']] | ||
|
@@ -512,6 +517,13 @@ export class ComfyApp { | |
} | ||
|
||
app.graph.setDirtyCanvas(true) | ||
|
||
if (node.images && app.nodeOutputs[node.id]) { | ||
useNodeOutputStore().nodeOutputs[node.id] = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [quality] medium Priority Issue: Potential race condition with nodeOutputs access |
||
...app.nodeOutputs[node.id], | ||
images: node.images | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[architecture] medium Priority
Issue: Direct mutation of node object properties
Context: Directly setting node.imageIndex and node.imgs bypasses Vue reactivity and violates immutability principles
Suggestion: Use a reactive store or emit events to parent components to handle state changes properly