ARCore android scenform:不能对多个 SceneView 使用同一个 ViewRenderable

ARCore android scenform :Cannot use the same ViewRenderable with multiple SceneViews

我的应用程序使用 arcore augmentedimages 进行图像检测,并在检测到图像后显示 viewrenderable。如果我在检测到图像并显示 viewrenderable 后关闭应用程序,然后重新打开应用程序,应用程序会在检测到图像后崩溃,抛出

IllegalStateException: Cannot use the same ViewRenderable with multiple SceneViews

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.techaffinity.arroutertroubleshoot, PID: 4313
    java.lang.IllegalStateException: Cannot use the same ViewRenderable with multiple SceneViews.
        at com.google.ar.sceneform.rendering.RenderViewToExternalTexture.attachView(RenderViewToExternalTexture.java:131)
        at com.google.ar.sceneform.rendering.ViewRenderable.attachToRenderer(ViewRenderable.java:303)
        at com.google.ar.sceneform.rendering.RenderableInstance.attachToRenderer(RenderableInstance.java:81)
        at com.google.ar.sceneform.Node.activate(Unknown Source)
        at com.google.ar.sceneform.Node.updateActiveStatusRecursively(Unknown Source)
        at com.google.ar.sceneform.Node.setEnabled(Unknown Source)
        at com.techaffinity.arroutertroubleshoot.augmentedImage.HighlightNode.setVisible(HighlightNode.java:65)
        at com.techaffinity.arroutertroubleshoot.augmentedImage.ModelNode.setChildVisible(ModelNode.java:69)
        at com.techaffinity.arroutertroubleshoot.augmentedImage.ARTroubleshootActivity.yesPressed(ARTroubleshootActivity.java:178)
        at com.techaffinity.arroutertroubleshoot.augmentedImage.ARTroubleshootActivity.lambda$TWxn4Gt1IyJ444bAiIcNiVnU0ng(ARTroubleshootActivity.java)
        at com.techaffinity.arroutertroubleshoot.augmentedImage.-$$Lambda$ARTroubleshootActivity$TWxn4Gt1IyJ444bAiIcNiVnU0ng.onClick(lambda)
        at android.view.View.performClick(View.java:5640)
        at android.view.View$PerformClick.run(View.java:22455)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6165)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)

崩溃发生在

的 onUpdateFrame 方法中
node.setRenderable(viewRenderableCF);
arFragment.getArSceneView().getScene().addChild(node);

where 'viewRenderableCF' is CompletableFuture of type ViewRenderable

我目前正在通过在 ondestroy() 方法中调用 System.exit(0) 来解决这个问题。

有没有更好的方法来做到这一点(从内存中清除应用程序,例如在最近的应用程序列表中滑动应用程序预览)?

有没有arcore相关的代码清除SceneView的实例?

试着调用这个 onDestroy/OnPause

arFragment.getArSceneView().getScene().onRemoveChild(node);

在 activity 的 onDestroy() 回调中将 CompletableFuture 设置为 null 可以解决问题。即使在调用 finish 方法之后,ViewRenderable 类型的 CompletableFuture 仍在内存中。当我再次转到相同的 activity 时,ViewRenderable 是从旧的 CompletableFuture 创建的。 ModelRenderable 类型的 CompletableFuture 也是这种情况,但由于我不知道的原因,将 modelrenderable 设置为节点不会导致此崩溃。