Skip to content

Commit

Permalink
Merge pull request #18336 from Snuffleupagus/InternalRenderTask-cance…
Browse files Browse the repository at this point in the history
…l-cancelAnimationFrame

Cancel the `requestAnimationFrame` in the API when cancelling rendering
  • Loading branch information
timvandermeij authored Jun 27, 2024
2 parents af16aa6 + a4f1a9a commit 53aca5f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 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,10 @@ class InternalRenderTask {
this.running = false;
this.cancelled = true;
this.gfx?.endDrawing();
if (this.#rAF) {
window.cancelAnimationFrame(this.#rAF);
this.#rAF = null;
}
InternalRenderTask.#canvasInUse.delete(this._canvas);

this.callback(
Expand Down Expand Up @@ -3391,7 +3397,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 53aca5f

Please sign in to comment.