Skip to content

Commit

Permalink
Merge pull request #628 from opl-/fix/reset-readers-before-reuse
Browse files Browse the repository at this point in the history
Fix readers not reset by Browser*Readers, causing invalid results
  • Loading branch information
werthdavid authored Dec 1, 2024
2 parents fac984c + 9590cd4 commit 70cd2fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/browser/BrowserCodeReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,12 @@ export class BrowserCodeReader {
* Call the encapsulated readers decode
*/
public decodeBitmap(binaryBitmap: BinaryBitmap): Result {
return this.reader.decode(binaryBitmap, this._hints);
try {
return this.reader.decode(binaryBitmap, this._hints);
} finally {
// Readers need to be reset before being reused on another bitmap.
this.reader.reset();
}
}

/**
Expand Down
7 changes: 6 additions & 1 deletion src/browser/BrowserMultiFormatReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export class BrowserMultiFormatReader extends BrowserCodeReader {
* attention to the hints set in the constructor function
*/
public decodeBitmap(binaryBitmap: BinaryBitmap): Result {
return this.reader.decodeWithState(binaryBitmap);
try {
return this.reader.decodeWithState(binaryBitmap);
} finally {
// Readers need to be reset before being reused on another bitmap.
this.reader.reset();
}
}
}

0 comments on commit 70cd2fa

Please sign in to comment.