litegraph.js icon indicating copy to clipboard operation
litegraph.js copied to clipboard

Connections incorrectly assumed during LGraphNode.prototype.configure

Open AdamantLife opened this issue 8 months ago • 1 comments

In litegraph.js:

// Lines 2571 to 2573
var link_info = this.graph ? this.graph.links[input.link] : null;
if (this.onConnectionsChange)
	this.onConnectionsChange( LiteGraph.INPUT, i, true, link_info, input ); //link_info has been created now, so its updated

// Lines 2588 to 2590
var link_info = this.graph 	? this.graph.links[output.links[j]] : null;
if (this.onConnectionsChange)
	this.onConnectionsChange( LiteGraph.OUTPUT, i, true, link_info, output ); //link_info has been created now, so its updated

The first line of code acknowledges that link_info may be null, but onConnectionsChange() is always called and is also unconditionally called with the connected argument as true (the comment also suggests that link_info will never be null).

I did a quick sanity check to make sure that- in practice- link_info can be null by cloning a node with a connected input and confirmed that the link_info of the newly initialized node was null. This also contradicts the comment that asserts link_info had been created.

It seems like onConnectionsChange should either be called only when link_info is not null (or is truthy), or the connected argument should be false if link_info == null.

AdamantLife avatar Jun 02 '24 04:06 AdamantLife