EddyVerbruggen / nativescript-ar

Augmented Reality NativeScript plugin
https://www.nativescript.org/blog/preview-of-augmented-reality-in-nativescript
MIT License
118 stars 36 forks source link

Problem adding models #90

Open Priemar opened 4 years ago

Priemar commented 4 years ago

Which platform(s) does your issue occur on?

Im working on an angular nativescript project, where i have one page which i navigate to (router) which contains nativescript-ar. After the nativescript-ar is loaded im adding a model when the user triggers the planeTapped event. Which works fine.

When im navigating away, or simply hiding the nativescript-ar component and showing it again (or navigating again to this page) everything looks fine. But when i am trying to add a model now, i get a null reference exception. This means no matter what i do i have to restart the app to add models again.

Stacktrace: : Uncaught (in promise): Error: java.lang.NullPointerException JS: com.google.ar.sceneform.utilities.Preconditions.checkNotNull(SourceFile:3) JS: com.google.ar.sceneform.Node.getRendererOrDie(SourceFile:429) JS: com.google.ar.sceneform.Node.activate(SourceFile:333) JS: com.google.ar.sceneform.Node.updateActiveStatusRecursively(SourceFile:315) JS: com.google.ar.sceneform.Node.setSceneRecursively(SourceFile:293) JS: com.google.ar.sceneform.Node.onAddChild(SourceFile:87) JS: com.google.ar.sceneform.NodeParent.addChild(SourceFile:13) JS: com.google.ar.sceneform.Node.setParent(SourceFile:35) JS: com.tns.Runtime.callJSMethodNative(Native Method) JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1209) JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1096) JS: com.tns.Runtime.callJSMethod(Runtime.java:1083) JS: com.tns.Runtime.callJSMethod(Runtime.java:1063) JS: com.tns.Runtime.callJSMethod(Runtime.java:1055) JS: com.tns.gen.java.util.function.Consumer.accept(Consumer.java:18)

I checked out the source of nativescript-ar and saw the problem is caused when setting the parent for the model: (file: ar.android.ts, function: addModel)

Its reproduceable with the pokemon demo (android). i.e. in the try before you buy view, just open the ar screen add a model close it an reopen it again and add a model again.

Before I will investigating more time i am looking forward that someone already fixed this problem and will share the solution here.

Thanks

Priemar commented 4 years ago

Found the problem and created a pull request.

Just wanted to add one more thing if someone came across the same problem: When using angular with NS router, and you are navigating away from your component where the AR control is in use you have to destroy it manually.

You can achieve this by listening to the 'Page.navigatingFromEvent' and call the 'disposeNativeView' method from the AR control.