1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

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.
This commit is contained in:
Jonas Jenwald 2024-06-26 17:17:02 +02:00
parent af16aa62ad
commit a4f1a9a41b

View file

@ -3254,6 +3254,8 @@ class RenderTask {
* @ignore
*/
class InternalRenderTask {
#rAF = null;
static #canvasInUse = new WeakSet();
constructor({
@ -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(
@ -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 {