From c6ffd3847890fcd8cdac429958e2014a9e76b5aa Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 26 Jun 2024 17:17:02 +0200 Subject: [PATCH] Cancel the `requestAnimationFrame` in the API when cancelling rendering 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. --- src/display/api.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/display/api.js b/src/display/api.js index 3b1ca159c6f2fa..dc1b8d7db66c60 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -3254,6 +3254,8 @@ class RenderTask { * @ignore */ class InternalRenderTask { + #rAF = null; + static #canvasInUse = new WeakSet(); constructor({ @@ -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( @@ -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 {