Skip to content

Empty graph does not clear canvas #210

@mmtftr

Description

@mmtftr

I am building a player with videocontext that allows clips to be added and removed.
When a clip is in view and the user deletes the clip, we destroy the video node, however the canvas is not cleared and the last frame that was rendered remains on screen.

I've found the reason to be that the Khan's algorithm used here is faulty because it does not consider the case where there are no connections and only one node (the DestinationNode)
(In this case sortedNodes is just an empty array instead of [this._destinationNode] which is the correct result)

let sortedNodes = [];
let connections = this._renderGraph.connections.slice();
let nodes = RenderGraph.getInputlessNodes(connections);
while (nodes.length > 0) {
let node = nodes.pop();
sortedNodes.push(node);
for (let edge of RenderGraph.outputEdgesFor(node, connections)) {
let index = connections.indexOf(edge);
if (index > -1) connections.splice(index, 1);
if (RenderGraph.inputEdgesFor(edge.destination, connections).length === 0) {
nodes.push(edge.destination);
}
}
}
for (let node of sortedNodes) {
if (this._sourceNodes.indexOf(node) === -1) {
node._update(this._currentTime);
node._render();
}
}

The problem is resolved if I manually call _render and _update on the DestinationNode when there aren't any connections via an override of the VideoContext class. I can actually make a PR for a simple hotfix by checking if connections.length===0 then setting sortedNodes to [this._destinationNode] if you'd like.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions