Attempt to clean-up/restore pending rendering operations when errors 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.
This commit is contained in:
Jonas Jenwald 2019-01-26 10:12:32 +01:00
parent 40863eb275
commit 5081063b9e
2 changed files with 8 additions and 9 deletions

View File

@ -2434,7 +2434,7 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
} }
} }
cancel() { cancel(error = null) {
this.running = false; this.running = false;
this.cancelled = true; this.cancelled = true;
if (this.gfx) { if (this.gfx) {
@ -2443,8 +2443,8 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
if (this._canvas) { if (this._canvas) {
canvasInRendering.delete(this._canvas); canvasInRendering.delete(this._canvas);
} }
this.callback(new RenderingCancelledException( this.callback(error || new RenderingCancelledException(
'Rendering cancelled, page ' + this.pageNumber, 'canvas')); `Rendering cancelled, page ${this.pageNumber}`, 'canvas'));
} }
operatorListChanged() { operatorListChanged() {
@ -2480,10 +2480,10 @@ const InternalRenderTask = (function InternalRenderTaskClosure() {
_scheduleNext() { _scheduleNext() {
if (this._useRequestAnimationFrame) { if (this._useRequestAnimationFrame) {
window.requestAnimationFrame(() => { window.requestAnimationFrame(() => {
this._nextBound().catch(this.callback); this._nextBound().catch(this.cancel.bind(this));
}); });
} else { } else {
Promise.resolve().then(this._nextBound).catch(this.callback); Promise.resolve().then(this._nextBound).catch(this.cancel.bind(this));
} }
} }

View File

@ -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 paintTask may have been replaced by a new one, so only remove
// the reference to the paintTask if it matches the one that is // the reference to the paintTask if it matches the one that is
// triggering this callback. // triggering this callback.
@ -442,7 +442,7 @@ class PDFPageView {
if (error instanceof RenderingCancelledException) { if (error instanceof RenderingCancelledException) {
this.error = null; this.error = null;
return Promise.resolve(undefined); return;
} }
this.renderingState = RenderingStates.FINISHED; this.renderingState = RenderingStates.FINISHED;
@ -465,9 +465,8 @@ class PDFPageView {
}); });
if (error) { if (error) {
return Promise.reject(error); throw error;
} }
return Promise.resolve(undefined);
}; };
let paintTask = this.renderer === RendererType.SVG ? let paintTask = this.renderer === RendererType.SVG ?