artoolkitx / jsartoolkit5

Javascript ARToolKit v5.x
https://artoolkitx.github.io/jsartoolkit5/examples/
Other
290 stars 67 forks source link

artoolkit.setup is not a function #40

Open ThorstenBux opened 6 years ago

ThorstenBux commented 6 years ago

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:

ThorstenBux commented 6 years ago

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

Flikker commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

Great - thank you very much! I will have a go with it and let you know. Thanks again

On Sun, 15 Jul 2018 at 20:25, Thorsten Bux notifications@github.com wrote:

@Flikker https://github.com/Flikker @Cobertos https://github.com/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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/artoolkitx/jsartoolkit5/issues/40#issuecomment-405112322, or mute the thread https://github.com/notifications/unsubscribe-auth/AMH8S9adyXISxP-AtmFRwFNYPS7YL5Z-ks5uG5c_gaJpZM4RV2WY .

kalwalt commented 5 years ago

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

ThorstenBux commented 5 years ago

What are you seeing? Which errors and issues?

kalwalt commented 5 years ago

as written in the pull request https://github.com/artoolkitx/jsartoolkit5/pull/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 commented 5 years ago

@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 commented 5 years ago

With the debug lib the app fails to enter in https://github.com/artoolkitx/jsartoolkit5/blob/b2a6c7529777999030773e02266799390482ba2a/js/artoolkit.api.js#L1855 in this way the function runWhenLoaded(); https://github.com/artoolkitx/jsartoolkit5/blob/b2a6c7529777999030773e02266799390482ba2a/js/artoolkit.api.js#L1856 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 commented 5 years ago

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

Inateno commented 3 years ago

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 commented 3 years ago

Check out webarkit in GitHub and ARnft

Kind regards Thorsten Bux

Sent from my iPhone

On 21/12/2020, at 12:29 AM, Rogliano Antoine notifications@github.com wrote:



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

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-trackinghttps://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Faframe.io%2Fblog%2Farjs3%2F%23getting-started-with-image-tracking&data=04%7C01%7C%7C6a1bd4daf59f458af91008d8a4da7a1e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637440605547533786%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=UKxE9KEjbNLm32d9BzrAE%2Bda%2Bt98WowFzDIzoxZXSWw%3D&reserved=0).

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">
  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 ^^'.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fartoolkitx%2Fjsartoolkit5%2Fissues%2F40%23issuecomment-748595151&data=04%7C01%7C%7C6a1bd4daf59f458af91008d8a4da7a1e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637440605547543745%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=DrvnZVdu%2Ba%2B3WIvGY14mUV2be82Pi0rjxIdRC6iTwmw%3D&reserved=0, or unsubscribehttps://apac01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAD765PDC7I3VAAHYXRMRBILSVXNYRANCNFSM4EKXMWMA&data=04%7C01%7C%7C6a1bd4daf59f458af91008d8a4da7a1e%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637440605547543745%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=xvSDMXcQGaxlkuUFyxrSomjtcfmeS3fk%2FVzYIIXkzos%3D&reserved=0.

Inateno commented 3 years ago

Check out webarkit in GitHub and ARnft Kind regards Thorsten Bux

Didn't knew that project, will do thanks !

kalwalt commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

@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 commented 3 years ago

@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 commented 2 years ago

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”;