2

I've created a cordova Android app where users tap a link and it starts jsartoolkit. It all works fine the first time, but if I tap the back button then open the link again, after a few times it fails with an error:

"typeerror: artoolkit.setup is not a function"

It's happening when it tries to load the ARCameraParam (Data/camera_para.dat) - I've tried loading it both directly into the arcontroller ie var arController = new ARController(video, 'Data/camera_para.dat') and also loading it first ie arCamera = new ARCameraParam.

This error suggests that artoolkit.min.js isn't loading after a few times but I'm bamboozled as to why that would be. It's not a caching issue - if I clear the app cache when it happens then try again, it still won't load. It always works fine the first time I've installed the app and also if I force stop the app, which suggests there's a process running from a previous session I'm not aware of. I've tried calling dispose on both the arcontroller and the arcameraparam when I tap the back button but that hasn't fixed it.

Does anyone know what processes jsartoolkit might be running that might cause an error like this? Any advice is very gratefully received. Relevant code:

window.ARThreeOnLoad = function() {
    function gotStream(stream) {
        camvideo.src = window.URL.createObjectURL(stream);  
        nextBit(camvideo);
        track = stream.getVideoTracks()[0];

camvideo.onerror = function(e) 
{   stream.stop();   };

stream.onended = noStream;
}

function noStream(e) {
        alert("no stream " + e);
        var msg = 'No camera available.';
    if (e.code == 1) {   
        msg = 'User denied access to use camera.';   }
        document.getElementById('errorMessage').textContent = msg;
     }



   var camvideo = document.getElementById('monitor'); 

   var constraints = { video: {facingMode: {exact: "environment"}, width: 1280, height: 960} };

    navigator.mediaDevices.getUserMedia(constraints).then(gotStream).catch(noStream);


}


function nextBit(video) {
    var arController = new ARController(video, 'Data/camera_para.dat');
    arController.onload = function() {
           arController.image = video;
quinz
  • 1,282
  • 4
  • 21
  • 33
Flikster
  • 21
  • 2
  • I'm having this same issue when I build it myself in Docker. Try using `artoolkit.debug.js`. This seems to work for me even when `artoolkit.min.js` doesn't, even though they're from the exact same build. Perhaps a minification issue? – Cobertos Feb 16 '18 at 13:43

0 Answers0