Skip to content

Commit f800c40

Browse files
AustinMrozDrJKL
andauthored
Fix zombie linkIds on node deletion, add safety check (#7153)
Resolves #7152 - Adds a safety check to make sure link exists. - Actually solves the problem by making sure the linkId is removed from the subgraphOutput node when a node is deleted. ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-7153-Fix-zombie-linkIds-on-node-deletion-add-safety-check-2bf6d73d365081d98583e6a987431bd1) by [Unito](https://www.unito.io) --------- Co-authored-by: Alexander Brown <[email protected]>
1 parent 3feeecc commit f800c40

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/lib/litegraph/src/LGraphNode.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { LayoutSource } from '@/renderer/core/layout/types'
1111
import { adjustColor } from '@/utils/colorUtil'
1212
import type { ColorAdjustOptions } from '@/utils/colorUtil'
1313

14+
import { SUBGRAPH_OUTPUT_ID } from '@/lib/litegraph/src/constants'
1415
import type { DragAndScale } from './DragAndScale'
1516
import type { LGraph } from './LGraph'
1617
import { BadgePosition, LGraphBadge } from './LGraphBadge'
@@ -45,8 +46,8 @@ import type {
4546
Rect,
4647
Size
4748
} from './interfaces'
48-
import { LiteGraph } from './litegraph'
49-
import type { LGraphNodeConstructor, Subgraph, SubgraphNode } from './litegraph'
49+
import { LiteGraph, Subgraph } from './litegraph'
50+
import type { LGraphNodeConstructor, SubgraphNode } from './litegraph'
5051
import {
5152
createBounds,
5253
isInRect,
@@ -3062,6 +3063,17 @@ export class LGraphNode
30623063
for (const link_id of links) {
30633064
const link_info = graph._links.get(link_id)
30643065
if (!link_info) continue
3066+
if (
3067+
link_info.target_id === SUBGRAPH_OUTPUT_ID &&
3068+
graph instanceof Subgraph
3069+
) {
3070+
const targetSlot = graph.outputNode.slots[link_info.target_slot]
3071+
if (targetSlot) {
3072+
targetSlot.linkIds.length = 0
3073+
} else {
3074+
console.error('Missing subgraphOutput slot when disconnecting link')
3075+
}
3076+
}
30653077

30663078
const target = graph.getNodeById(link_info.target_id)
30673079
graph._version++

src/lib/litegraph/src/subgraph/SubgraphOutput.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export class SubgraphOutput extends SubgraphSlot {
158158
//should never have more than one connection
159159
for (const linkId of this.linkIds) {
160160
const link = subgraph.links[linkId]
161+
if (!link) continue
161162
subgraph.removeLink(linkId)
162163
const { output, outputNode } = link.resolve(subgraph)
163164
if (output)

0 commit comments

Comments
 (0)