Skip to content

Commit

Permalink
Attempt to clean-up/restore pending rendering operations when errors …
Browse files Browse the repository at this point in the history
…occurs while a `RenderTask` runs (PR 10202 follow-up)

This piggybacks of the existing `cancel` functionality, to ensure that any pending operations are closed *and* that any temporary canvases are actually being removed.

Also simplifies `finishPaintTask` in `PDFPageView.draw` slightly, by converting it to an async function.
  • Loading branch information
Snuffleupagus committed Jan 26, 2019
1 parent 40863eb commit 75b9cef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/display/api.js
Expand Up @@ -2434,7 +2434,7 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
}
}

cancel() {
cancel(error = null) {
this.running = false;
this.cancelled = true;
if (this.gfx) {
Expand All @@ -2443,8 +2443,8 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
if (this._canvas) {
canvasInRendering.delete(this._canvas);
}
this.callback(new RenderingCancelledException(
'Rendering cancelled, page ' + this.pageNumber, 'canvas'));
this.callback(error || new RenderingCancelledException(
`Rendering cancelled, page ${this.pageNumber}`, 'canvas'));
}

operatorListChanged() {
Expand Down Expand Up @@ -2480,10 +2480,10 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
_scheduleNext() {
if (this._useRequestAnimationFrame) {
window.requestAnimationFrame(() => {
this._nextBound().catch(this.callback);
this._nextBound().catch(this.cancel.bind(this));
});
} else {
Promise.resolve().then(this._nextBound).catch(this.callback);
Promise.resolve().then(this._nextBound).catch(this.cancel(this));
}
}

Expand Down
7 changes: 3 additions & 4 deletions web/pdf_page_view.js
Expand Up @@ -432,7 +432,7 @@ class PDFPageView {
};
}

let finishPaintTask = (error) => {
const finishPaintTask = async (error) => {
// The paintTask may have been replaced by a new one, so only remove
// the reference to the paintTask if it matches the one that is
// triggering this callback.
Expand All @@ -442,7 +442,7 @@ class PDFPageView {

if (error instanceof RenderingCancelledException) {
this.error = null;
return Promise.resolve(undefined);
return;
}

this.renderingState = RenderingStates.FINISHED;
Expand All @@ -465,9 +465,8 @@ class PDFPageView {
});

if (error) {
return Promise.reject(error);
throw error;
}
return Promise.resolve(undefined);
};

let paintTask = this.renderer === RendererType.SVG ?
Expand Down

0 comments on commit 75b9cef

Please sign in to comment.