Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to read QR code. Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS. #74

Open
ollietb opened this issue Sep 1, 2017 · 7 comments

Comments

@ollietb
Copy link

ollietb commented Sep 1, 2017

I'm getting this error on an application which is scanning multiple QR codes over long periods

Failed to read QR code. Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS.

@schmich could you please recompile the script with more pointers as described here

@lnorbert
Copy link

We ran into the same issue. When trying to scan the 21st QR code, our app failed to start Instascan.

We changed Instascan's Analyzer class to re-use the ZXing function pointer it created the first time it was initialised.

The affected file:
https://github.com/schmich/instascan/blob/master/src/scanner.js

diff --git a/src/scanner.js b/src/scanner.js
index cdfaa78..5043b29 100644
--- a/src/scanner.js
+++ b/src/scanner.js
@@ -96,14 +96,16 @@ class Analyzer {
     this.canvas.style.display = 'none';
     this.canvasContext = null;

-    this.decodeCallback = ZXing.Runtime.addFunction(function (ptr, len, resultIndex, resultCount) {
-      let result = new Uint8Array(ZXing.HEAPU8.buffer, ptr, len);
-      let str = String.fromCharCode.apply(null, result);
-      if (resultIndex === 0) {
-        window.zxDecodeResult = '';
-      }
-      window.zxDecodeResult += str;
-    });
+    if(!Analyzer.decodeCallback) {
+        Analyzer.decodeCallback = ZXing.Runtime.addFunction(function (ptr, len, resultIndex, resultCount) {
+          let result = new Uint8Array(ZXing.HEAPU8.buffer, ptr, len);
+          let str = String.fromCharCode.apply(null, result);
+          if (resultIndex === 0) {
+            window.zxDecodeResult = '';
+          }
+          window.zxDecodeResult += str;
+        });
+    }
   }

   analyze() {
@@ -142,7 +144,7 @@ class Analyzer {
       ZXing.HEAPU8[this.imageBuffer + j] = Math.trunc((r + g + b) / 3);
     }

-    let err = ZXing._decode_qr(this.decodeCallback);
+    let err = ZXing._decode_qr(Analyzer.decodeCallback);
     if (err) {
       return null;
     }

I didn't do a PR as they seem to be not merged anyway and I have no Idea how this solution complies with the coding standards of Instascan.

adammcfadden added a commit to adammcfadden/instascan that referenced this issue Oct 31, 2017
@eko
Copy link

eko commented Nov 23, 2017

Hello @schmich, we encounter issues and would be interested in this fix too. Could you please merge it and create a new tag for it?

Thank you

@eko
Copy link

eko commented Nov 28, 2017

@adammcfadden Hello, could you please propose a pull request in order to get this fix merged?

@adammcfadden
Copy link

I opened a pull request with the change proposed above by @lnorbert . I am currently using a minified version of instascan with that implementation, and it has been working fine so far. I haven't vetted the solution any further than that, and am not sure of the performance implecations of this change.

PR is at: #109

I created a release on the forked repo to provide minified source code that includes the patch. https://github.com/adammcfadden/instascan/releases/tag/1.0.0-patch%2374

Once the changes are merged into schmich/instascan I'll take down the forked repo, but until then I'll leave it up in case anyone needs this specific fix.

@eko thanks for the reminder, this one fell off my radar for a while.

@schmich if you have any ideas on improving this patch let me know, I would be happy to help out where I can.

@eko
Copy link

eko commented Nov 29, 2017

Thank you so much, I’ve also tried to send an email to @schmich. I hope he wiii find some time to have a look at this PR.

@jackocnr
Copy link

Oh no, 1 year later and still nothing? :(

I'm also experiencing this problem. Looks like Adam McFadden's fork is still up-to-date tho so I guess I'll try that.

@mathias999us
Copy link

Not sure if anyone made any progress on this, but I ran into this problem also. This is apparently just that you must call removeFunction(ptr) once you are done with that callback registration. ZXing is apparently internally limited to 20 registered callback pointers (although this can apparently be adjusted somewhere). The callbacks however can be invoked an unlimited number of times. Not sure why one would need more than 20 callback handlers registered on a single page at a given time, so this is probably just a misunderstanding of how to use the zxing api.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants