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

artoolkit.setup is not a function #40

Open
ThorstenBux opened this issue Jan 8, 2018 · 24 comments
Open

artoolkit.setup is not a function #40

ThorstenBux opened this issue Jan 8, 2018 · 24 comments
Assignees

Comments

@ThorstenBux
Copy link

Issue by Flikker
Wednesday Sep 27, 2017 at 09:07 GMT
Originally opened as https://github.com/artoolkit/jsartoolkit5/issues/66


I've got jsartoolkit working fine in an Android Cordova app - users click on a link (window.open) and jsartoolkit launches. But if I tap the back button then click on the link again, after a couple of times I get a nostream error saying "Typeerror: artoolkit.setup is not a function". I've pinpointed that it happens when it tries to load the ARCameraParam (Data/camera_para.dat).
It always works fine the first time and if I force close the app then try again.
Anyone know what might be going wrong?
A few possible issues I've thought through:

  • It always works the first time, so is there a process running that's preventing it working on subsequent loads, or preventing artoolkit.min.js from loading?
  • I don't think it's a caching issue; if I go into Settings and clear the app cache when it happens then try it again, it still doesn't work.
  • I've tried arcontroller.dispose to see if that was an issue; it didn't help, but maybe I wasn't using it correctly.
    Thank you for any help or insights you're able to give!
@ThorstenBux
Copy link
Author

@Flikker I'd need some more information on that.

@ThorstenBux ThorstenBux self-assigned this Jan 8, 2018
@Flikker
Copy link

Flikker commented Jan 8, 2018

Thanks for the reply @ThorstenBux
What info would be useful for you? Or do you want me to send you the app to try, or all of the code?
I've since tried adding all of the code from artoolkit.min.js into my main js file and the issue persists, so it's not a problem with loading artoolkit.min.js - it seems to be that half of it loads then fails at artoolkit.setup. I presume it's failing at the stage

`arController = new ARController(video, arCamera);

arController.onload = function()...`

because that's where the artoolkit.setup gets used.

@ThorstenBux
Copy link
Author

Very wired, you've got a special setup using Cordova which I haven't tested. At the moment I cannot say what is going on :(

@Flikker
Copy link

Flikker commented Jan 13, 2018

Thanks @ThorstenBux
I've been trying to solve it for quite a while but I've still got some ideas of things to check, so I will let you know if I come across the issue and its solution.
In the meantime, are there any areas you can point me towards that you think are worth me checking? I appreciate that it's difficult for you to say without looking into it, but off the top of your head if there are any general potential causes of the issue that you think I should explore then that would be useful. Thanks again!

@Cobertos
Copy link

Cobertos commented Feb 16, 2018

I get this same issue when I build master. It only seems to be a problem with the artoolkit.min.js and the artoolkit.debug.js works fine. Perhaps a minification issue?

@Flikker Try using artoolkit.debug.js and see if that works?

EDIT: Did a deep dive. Tested out exposePublicSymbol() and replacePublicSymbol() in artoolkit.(min|debug).js (which expose the setup() function and they seem to work fine. However, when the Module object from the asm library gets to runWhenLoaded() (in artoolkit.api.js), the functions are undefined in min but not in debug and artoolkit.api.js.

Looking at my built version of artoolkit.min.js (which seems different from the one in the repo, even though I'm building with master and the tutorial provided in docker), there's an extra statement at the start of artoolkit.min.js which master doesn't have in build:

var Module=typeof Module!=="undefined"?Module:{};

I noticed that this also appears the top of artoolkit.debug.js.

Because that statement is there, it defines Module before the --pre-js included artoolkit.api.js is ran in artoolkit.min.js and when it gets to the bottom of artoolkit.api.js, it assumes the existance of Module means the library has loaded and then it doesn't find the symbol so it fails.

As for why this statement gets reordered before --pre-js, I'm unsure yet. A fix would be to have a different check at the bottom of artoolkit.api.js (instead of just Module it checks a property on Module). I'm looking into what part of the build messes this up.

@Flikker
Copy link

Flikker commented May 10, 2018

Hi there @Cobertos - sorry for the slow reply. Thanks very much for sharing all the digging you've done on this one; very useful, and it's not an issue I'd considered. I've tried using the debug version but unfortunately it still doesn't seem to have solved the issue for me. At a bit of a loss as to what to try next!
Have there been any changes that might have affected this in the meantime @ThorstenBux ?
Thanks again.

@ThorstenBux
Copy link
Author

@Flikker no changes that I'd be aware of.

As for @Cobertos observation that the prebuild libs inside the repo differ from manually built once, I'm almost certain that the prebuild libs are outdated. So I encourage everyone to build manually.

@ThorstenBux
Copy link
Author

As it happens I just did a build on my machine and can see that there is the

var Module=typeof Module!=="undefined"?Module:{}

definition inside artoolkit.debug.js and artoolkit.min.js

@ThorstenBux
Copy link
Author

@Flikker @Cobertos I've done some changes in regards to this. You could checkout the latest master and build. Please let me know if that helps

@Flikker
Copy link

Flikker commented Jul 16, 2018 via email

@kalwalt kalwalt mentioned this issue Feb 13, 2019
@kalwalt
Copy link

kalwalt commented Feb 13, 2019

This issue is still present, 😭 I just tested the master branch, @ThorstenBux where are these new changes in the code? Are you sure they are in the master?

@ThorstenBux
Copy link
Author

What are you seeing? Which errors and issues?

@kalwalt
Copy link

kalwalt commented Feb 13, 2019

as written in the pull request #79 i get this:

I receive this error running the simple_video.html example ( and the others using the debug lib):

artoolkit.api.js:1148 Uncaught TypeError: artoolkit.setup is not a function
    at ARController._initialize (artoolkit.api.js:1148)
    at ARController.<anonymous> (artoolkit.api.js:111)
    at ARCameraParam.<anonymous> (artoolkit.api.js:1591)
    at writeCallback (artoolkit.api.js:1785)
    at writeByteArrayToFS (artoolkit.api.js:1811)
    at XMLHttpRequest.oReq.onload (artoolkit.api.js:1828) 

i saw this issue #40 but it seems that now the debug lib is affected and not the minifyied lib...

The video (from Data/output_4.mp4) start and it is displayed but the debug draw not.
instead with the simple_image.html example the debug draw works as expected. I don't understand why this happens...

@kalwalt
Copy link

kalwalt commented Feb 14, 2019

@ThorstenBux another aspect of the issue, in the simple_rtc.html example i get a different error:

success MediaStream {id: "GcE77sFhwrrfIw19fM0rc4lJkPtPxAXxD86x", active: true, onaddtrack: null, onremovetrack: null, onactive: null, …}
artoolkit.api.js:1556 onload callback should be defined
ARCameraParam @ artoolkit.api.js:1556
success @ simple_rtc.html:55
artoolkit.api.js:1562 onerror callback should be defined
ARCameraParam @ artoolkit.api.js:1562
success @ simple_rtc.html:55
125710artoolkit.api.js:1148 Uncaught TypeError: artoolkit.setup is not a function
    at ARController._initialize (artoolkit.api.js:1148)
    at new ARController (artoolkit.api.js:120)
    at simple_rtc.html:64
ARController._initialize @ artoolkit.api.js:1148
ARController @ artoolkit.api.js:120
(anonymous) @ simple_rtc.html:64
setInterval (async)
cameraParam.onload @ simple_rtc.html:60
(anonymous) @ artoolkit.api.js:1591
writeCallback @ artoolkit.api.js:1785
writeByteArrayToFS @ artoolkit.api.js:1811
oReq.onload @ artoolkit.api.js:1828
load (async)
ajax @ artoolkit.api.js:1823
loadCamera @ artoolkit.api.js:1792
ARCameraParam.load @ artoolkit.api.js:1588
ARCameraParam @ artoolkit.api.js:1568
success @ simple_rtc.html:55

note the warnings about onLoad callback functions not defined ( that is not correct because they exist, right?)

@kalwalt
Copy link

kalwalt commented Feb 15, 2019

With the debug lib the app fails to enter in

window.Module.onRuntimeInitialized = function() {

in this way the function runWhenLoaded();
runWhenLoaded();

is never loaded.
see also this report:

message: "Cannot read property 'onRuntimeInitialized' of undefined"
stack: "TypeError: Cannot read property 'onRuntimeInitialized' of undefined
at eval (eval at <anonymous> (extensions::messaging:235:9), <anonymous>:1:15)
at extensions::messaging:235:9"
__proto__: Error

i solved moving the runWhenLoaded() function before the onRuntimeInitialized:

if (window.Module) {
		console.log('window module exist:',window.Module);
		runWhenLoaded();
		window.Module.onRuntimeInitialized = function() {
			      console.log('we enter in the Runtime!');
                              var event = new Event('artoolkit-loaded');
                              window.dispatchEvent(event);
        }

not sure that is correct but at least a temporary solution.
For sure i don't receive any message from the event dispatching but only that from the console log.

@kalwalt
Copy link

kalwalt commented Feb 15, 2019

I leave this link as a reminder: about onRuntimeInitialized with emscripten

@Inateno
Copy link

Inateno commented Dec 20, 2020

How this can still not be fixed it's incredible, does no-one use this or no-one use ES6 imports?

I'm occuring the same issue, if I go with the "getting started" I have this error when I get files locally (cf this link https://aframe.io/blog/arjs3/#getting-started-with-image-tracking).

If I use the distant tags (same as example) it is fine, but if I follow the links, save the JS files and load them in ES6, I receive this error (I don't need to do any more code than just loading).

So what I do is, open
https://aframe.io/releases/1.0.4/aframe.min.js and https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js save them locally and import in a JS files with ES6.

import 'aframe';
import './aframe-ar-nft';

And the error occurs artoolkit.setup is not a function (from the nft)

I have this code in the top html file but doesn't help a lot

  <script type="text/javascript">
      if (!window.navigator.xr.requestDevice) {
        window.navigator.xr.requestDevice = function () {
          return new Promise((r) => r(window.navigator.xr));
        };
      }
    </script>
    <script type="text/javascript">
      var Module = {
        onRuntimeInitialized: function () {
          Module._foobar(); // foobar was exported
        },
      };
    </script>

Would be nice if those repo could work with a "simple" npm i, I managed to make aframe-ar works in ES6 but tooks me long, know I'm stuck with this nft version ^^'.

@ThorstenBux
Copy link
Author

ThorstenBux commented Dec 20, 2020 via email

@Inateno
Copy link

Inateno commented Dec 20, 2020

Check out webarkit in GitHub and ARnft Kind regards Thorsten Bux

Didn't knew that project, will do thanks !

@kalwalt
Copy link

kalwalt commented Dec 20, 2020

yes, as @ThorstenBux said, if you are only interested to NFT marker try our webarkit/ARnft but it has not direct aframe support for now (but i'm working on). Hope that will help.

@Inateno
Copy link

Inateno commented Dec 20, 2020

We are using a-frame because that's actually the solution that work the "best" out of the box, when you try to get every project aside and wrap them together in an ES6 project it's quite a nightmare lol

So yeah I'll, I put the repo in fav and will give it a try once we need for a next project ! Thanks.

@kalwalt
Copy link

kalwalt commented Dec 20, 2020

@Inateno consider also that there is a PR to add ES6 support to Ar.js. Sad news has not so much time to push in that effort, 😭 Can't do everything..

@Inateno
Copy link

Inateno commented Dec 20, 2020

@kalwalt Ahah don't worry I know that pretty much same here ! ^^
Just sad to see that many years after, doing web ar isn't "ready to go" and not mature yet.

@DLGL99GL
Copy link

DLGL99GL commented Nov 30, 2021

How this can still not be fixed it's incredible, does no-one use this or no-one use ES6 imports?

I'm occuring the same issue, if I go with the "getting started" I have this error when I get files locally (cf this link https://aframe.io/blog/arjs3/#getting-started-with-image-tracking).

If I use the distant tags (same as example) it is fine, but if I follow the links, save the JS files and load them in ES6, I receive this error (I don't need to do any more code than just loading).

So what I do is, open https://aframe.io/releases/1.0.4/aframe.min.js and https://raw.githack.com/AR-js-org/AR.js/master/aframe/build/aframe-ar-nft.js save them locally and import in a JS files with ES6.

import 'aframe';
import './aframe-ar-nft';

And the error occurs artoolkit.setup is not a function (from the nft)

I have this code in the top html file but doesn't help a lot

  <script type="text/javascript">
      if (!window.navigator.xr.requestDevice) {
        window.navigator.xr.requestDevice = function () {
          return new Promise((r) => r(window.navigator.xr));
        };
      }
    </script>
    <script type="text/javascript">
      var Module = {
        onRuntimeInitialized: function () {
          Module._foobar(); // foobar was exported
        },
      };
    </script>

Would be nice if those repo could work with a "simple" npm i, I managed to make aframe-ar works in ES6 but tooks me long, know I'm stuck with this nft version ^^'.

hello @Inateno What was your final solution?
i want to add the function of “multi_nft.html” into hololens by three.js,I've got the same error;
“Check out webarkit in GitHub and ARnft”,i used (https://github.com/webarkit/jsartoolkit5) should be the latest project,but “artoolkit.setup is not a function”;

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

No branches or pull requests

6 participants