bbc / VideoContext

An experimental HTML5 & WebGL video composition and rendering API.
http://bbc.github.io/VideoContext/
Apache License 2.0
1.32k stars 157 forks source link

Empty graph does not clear canvas #210

Open mmtftr opened 4 years ago

mmtftr commented 4 years ago

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)

https://github.com/bbc/VideoContext/blob/5f82048cc36a87e64d5b855befc4ff08ec1a169a/src/videocontext.js#L941-L962

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.