Skip to content

Commit

Permalink
Fix infinite PDF ink/image annotation image rendering loop
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Oct 13, 2023
1 parent eedbf6d commit 79a1cd3
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/pdf/pdf-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ class PDFRenderer {
constructor(options) {
this._pdfView = options.pdfView;
this._processing = false;
this._lastRendered = new Map();
}

async _renderNext(previousAnnotationID) {
async _renderNext() {
if (this._processing) {
return;
}
this._processing = true;
let annotation = this._pdfView._annotations.find(x => ['image', 'ink'].includes(x.type) && !x.image);
// If for some reason trying to process the same annotation, stop to avoid infinite loop
if (annotation && previousAnnotationID !== annotation.id) {
let image = await this._renderAnnotationImage(annotation);
setTimeout(() => this._renderNext(annotation.id));
if (image) {
this._pdfView._onUpdateAnnotations([{ id: annotation.id, image }]);
if (annotation) {
let lastRendered = this._lastRendered.get(annotation.id);
if (!lastRendered || lastRendered < annotation.dateModified) {
this._lastRendered.set(annotation.id, annotation.dateModified);
let image = await this._renderAnnotationImage(annotation);
if (image) {
this._pdfView._onUpdateAnnotations([{ id: annotation.id, image }]);
}
setTimeout(() => this._renderNext());
}
}
this._processing = false;
}

async _renderAnnotationImage(annotation) {
Expand Down

0 comments on commit 79a1cd3

Please sign in to comment.