Skip to content
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

Empty graph does not clear canvas #210

Open
mmtftr opened this issue Sep 21, 2020 · 0 comments
Open

Empty graph does not clear canvas #210

mmtftr opened this issue Sep 21, 2020 · 0 comments

Comments

@mmtftr
Copy link

mmtftr commented Sep 21, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant