Skip to content

Commit

Permalink
Cancel the requestAnimationFrame in the API when cancelling rendering
Browse files Browse the repository at this point in the history
Errors related to this `requestAnimationFrame` show up intermittently when running the integration-tests on the bots, however I've been unable to reproduce it locally.
Hence I cannot guarantee that it's enough to fix the timing issues, however this should be generally safe since the `requestAnimationFrame` invokes the `_next`-method and the first thing that one does is check that rendering hasn't been cancelled.
  • Loading branch information
Snuffleupagus committed Jun 26, 2024
1 parent af16aa6 commit c6ffd38
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,8 @@ class RenderTask {
* @ignore
*/
class InternalRenderTask {
#rAF = null;

static #canvasInUse = new WeakSet();

constructor({
Expand Down Expand Up @@ -3353,6 +3355,8 @@ class InternalRenderTask {
this.running = false;
this.cancelled = true;
this.gfx?.endDrawing();
window.cancelAnimationFrame(this.#rAF);
this.#rAF = null;
InternalRenderTask.#canvasInUse.delete(this._canvas);

this.callback(
Expand Down Expand Up @@ -3391,7 +3395,8 @@ class InternalRenderTask {

_scheduleNext() {
if (this._useRequestAnimationFrame) {
window.requestAnimationFrame(() => {
this.#rAF = window.requestAnimationFrame(() => {
this.#rAF = null;
this._nextBound().catch(this._cancelBound);
});
} else {
Expand Down

0 comments on commit c6ffd38

Please sign in to comment.