Exception when multiple decodeSingle is requested
See original GitHub issueFirst, allow me to thank you for this high quality barcode library.
I tried to use quaggaJS in an express nodejs application. I noticed an exception could be encountered randomly when multiple request being send. I wrote the following test code snippet and am able to reproduce the problem, on another computer. (Both windows 10)
var Quagga = require('quagga').default;
for(var i=0;i<10;i++){
setTimeout(()=>{
Quagga.decodeSingle({
src: "image.jpg",// The image doesn't seem matter, I used a sample image from the repo
numOfWorkers: 0, // Needs to be 0 when used within node
inputStream: {
size: 800 // restrict input-size to be 800px in width (long-side)
},
decoder: {
readers: ["code_128_reader"] // List of active readers
},
}, function(result) {
if(result.codeResult) {
console.log("result", result.codeResult.code);
} else {
console.log("not detected");
}
});
},0);
}
I run the this snippet multiple times, sometimes an exception would happen. The following is the result from two consecutive run
C:\Development\quaggaJSTest>node index.js
[ 640, 480, 4 ]
[ 640, 480, 4 ]
[ 640, 480, 4 ]
[ 640, 480, 4 ]
[ 640, 480, 4 ]
[ 640, 480, 4 ]
[ 640, 480, 4 ]
[ 640, 480, 4 ]
[ 640, 480, 4 ]
[ 640, 480, 4 ]
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
result FANAVF14617104
result FANAVF14617104
result FANAVF14617104
result FANAVF14617104
result FANAVF14617104
result FANAVF14617104
result FANAVF14617104
result FANAVF14617104
FrameGrabber {"videoSize":[640,480],"canvasSize":[800,600],"stepSize":[0.8,0.8],"size":[800,600],"topRight":{"x":0,"y":0}}
result FANAVF14617104
result FANAVF14617104
C:\Development\quaggaJSTest>node index.js
[ 640, 480, 4 ]
[ 640, 480, 4 ]
C:\Development\quaggaJSTest\node_modules\quagga\lib\quagga.js:6620
inputStream.setWidth(Math.floor(Math.floor(size.x / patchSize.x) * (1 / halfSample) * patchSize.x));
^
TypeError: Cannot read property 'x' of null
at Object.checkImageConstraints (C:\Development\quaggaJSTest\node_modules\quagga\lib\quagga.js:6620:71)
at canRecord (C:\Development\quaggaJSTest\node_modules\quagga\lib\quagga.js:4158:32)
at publishEvent (C:\Development\quaggaJSTest\node_modules\quagga\lib\quagga.js:4766:30)
at Timeout._onTimeout (C:\Development\quaggaJSTest\node_modules\quagga\lib\quagga.js:4755:18)
at tryOnTimeout (timers.js:232:11)
at Timer.listOnTimeout (timers.js:202:5)
C:\Development\quaggaJSTest>
Is this an issue?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Exception when multiple decodeSingle is requested
I tried to use quaggaJS in an express nodejs application. I noticed an exception could be encountered randomly when multiple request being send....
Read more >Swift 5 Default Decododable implementation with only one ...
Is there a way to keep Swift's default implementation for a Decodable class with only Decodable objects but one exception. Unfortunately no.
Read more >Resolved Problems for Service Pack 1 - Oracle Help Center
Exceptions were not correctly handled when viewing the JNDI tree for a Managed Server. ... When multiple JMS Servers were configured and new...
Read more >Pipelining Review -- Mark Smotherman - Clemson University
operand forwarding paths, full network, clustered subnets, multi-cycle ... entry, multiple exits). interrupt/faults/exceptions complicate pipeline design.
Read more >Symbol DS3408 - Product Reference Guide - Barcode Datalink
lists of required steps that are not necessarily sequential. • Sequential lists (e.g., those that ... Other parameters require scanning several bar codes....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same issue when running the code multiple times without the first instance finishing. For those looking for a quick fix, you may want to create some sort of queue to process barcodes one at a time. I did this by creating an array that would act as a queue and pushing image file paths to it upon requesting for a barcode scan. If the scanning process hasn’t started yet on one of the barcodes, use a for loop to scan each barcode and do what you need to do with it one at a time; otherwise, do nothing. This would be controlled by a boolean flag stating if this loop is already running in the background. Observe:
I think the error occurs, because the Quagga module override its ‘module global variables’ (I call them so, because I don’t know the right term) like _inputStream, _framegrabber, … and so on with every call to .decodeSingle(…)
I changed the code in quagga.js for testing purposes in two places (Change #1, Change#2). Now exports.default exports a function, which encapsulate the whole code including the variables and returns the object with .decodeSingle(…) in it.
and use it like that:
Maybe some experienced javascript developer can review this. Could this be a valid solution for this problem?