newcat / baklavajs

Graph / node editor in the browser using VueJS
http://baklava.tech
MIT License
1.52k stars 113 forks source link

Critical error on Subgraph creation #345

Closed yojeek closed 8 months ago

yojeek commented 9 months ago

To reproduce just create subgraph.

Looks like regression after https://github.com/newcat/baklavajs/commit/15a45c4a8eb35fc0a98248ce4c7ae0c066369df5

dependencyEngine.ts:117 Uncaught (in promise) Error: Could not find value for interface 1a0bdee1-baf8-4b9a-befe-783a77dc222c
This is likely a Baklava internal issue. Please report it on GitHub.
    at DependencyEngine.getInterfaceValue (dependencyEngine.ts:117:19)
    at DependencyEngine.runGraph (dependencyEngine.ts:48:33)
    at GraphNode.calculate (graphNode.ts:68:84)
    at DependencyEngine.runGraph (dependencyEngine.ts:44:29)
    at async DependencyEngine.execute (dependencyEngine.ts:107:16)
    at async DependencyEngine.runOnce (baseEngine.ts:195:28)
    at async DependencyEngine.calculateWithoutData (baseEngine.ts:278:16)

But probably the core reason is an attempt to recalculate subgraph while it's being destroyed https://github.com/newcat/baklavajs/blob/master/packages/core/src/graphNode.ts#L130 :

        private initialize() {
            if (this.subgraph) {
                this.subgraph.destroy();
            }
            this.subgraph = this.template.createGraph();
            this._title = this.template.name;
            this.updateInterfaces();
            this.events.update.emit(null);
        }
chuteany commented 9 months ago

I've encountered the same issue. As shown in the screenshot below, I created a Subgraph, and when I clicked the Save Subgraph button, an error was logged in the console

Snipaste_2023-11-28_14-18-14

image

newcat commented 8 months ago

This is a pretty big issue - both in terms of severity, as well as complexity unfortunately. In essence, the changes introduced by #328 added a conflicting system for how to handle inputs/outputs for graphs. Previously, I had separate inputs and outputs properties for graphs and graph templates, which acted as "virtual" input and output nodes. Now, the nodes are actually part of the graph, which is a nice change IMO. However, it creates a redundancy between the inputs/outputs properties and the subgraph input/output nodes. During calculations, the input values for the node interfaces coming from outside the graph are directly applied based on the inputs graph property. But since the subgraph input nodes are treated as normal nodes now, the engine expects them to have output values, which they don't have at the moment.

Ideally, I would just let the subgraph input nodes emit the outside value as their output value but I had a few issues when implementing it. In addition, I'd like to consolidate the input/output properties and input/output subgraph nodes, which is hard to do without creating breaking changes. I am working on it, but due to the complexity of the issue and the limited time I have available at the moment, it might still take a few more weeks until I am able to push a fix.