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

Problem adding models #90

Open
Priemar opened this issue Nov 27, 2019 · 1 comment
Open

Problem adding models #90

Priemar opened this issue Nov 27, 2019 · 1 comment

Comments

@Priemar
Copy link
Contributor

Priemar commented Nov 27, 2019

Which platform(s) does your issue occur on?

  • Android
  • Version: Android 10
  • Device

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
Copy link
Contributor Author

Priemar commented Nov 28, 2019

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.

EddyVerbruggen added a commit that referenced this issue Nov 28, 2019
fixed (ar.android) fixed error when adding model after ar is recreated (#90)
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

1 participant