Open nuudles opened 5 years ago
@dam00n Could I provide any more information to be helpful in debugging this issue? As of right now this is a gating issue that is preventing the release of our app as most of the time the app simply crashes when the user leaves the AR experience.
Hey @nuudles, thanks for reaching out, we are currently taking a look at this issue to determine root cause.
Hey @nuudles, to test the above, i've created an activity that toggles between two fragments: First Fragment - An Android Fragment with basic 2D Android UI controls Second Fragment - An ViroARView with AR elements.
As seen in the video below, I am able to toggle between the fragments multiple times and transact between them. As such, I am not able to reproduce the issue you are currently seeing above.
One thing i did notice above is that you might be calling the ViroView activity lifecycles within the activity. This only makes sense if the activity is contains the viro view and thus directly handles it.
However, if the ViroView is now contained within a Fragment, because the fragment has it's own lifecycles, the above ViroView lifecycle callbacks thus must be handled in the fragment, Not the activity.
Let me know if you have any additional questions.
Thanks for the followup @dthian. We're definitely handling the ViroView lifecycle callbacks only in the container fragment. The activity doesn't know anything about the ViroView. Unfortunately it's very hard for us to debug what the issue might be since it's crashing in the ViroCore C framework.
Ah gotcha, one thing i did notice is a crash when mViroView.onActivityDestroyed() is called within the onDestroy callback of the Fragment's lifecycle.
Instead of calling it there, could you instead trigger it within the Fragment's onStop() callback of the lifecycle (right after mViroView.onActivityStopped(getActivity());)?
Looking at Android's Fragment lifecycle, it actually makes more sense to trigger it there instead.
@Override
public void onStop() {
super.onStop();
mViroView.onActivityStopped(getActivity());
mViroView.onActivityDestroyed(getActivity());
}
@dthian Thanks for the tip. Unfortunately that did not solve the segfault, but we took a closer look and think we found the root cause. We were using a FrameListener
to detect user interaction with the scene, specifically by calling getLastCameraPositionRealtime
. I guess the callback was still getting called right as the Fragment (and therefore while the ViroView) was being destroyed, and the crash specifically happens when that getLastCameraPositionRealtime
gets called. I'm not sure if that is proper behavior or not, but we were able to work around the issue by setting the FrameListener
to null
on tear down:
@Override
public void onStop() {
super.onStop();
viroView.setFrameListener(null);
viroView.onActivityStopped(getActivity());
viroView.onActivityDestroyed(getActivity());
}
I'm having the same issue, for what I think is the same reason: getLastCameraPositionRealTime() except I was calling it from mViroView.CameraListener.onTransformUpdate(). I was thinking of using FrameListener instead, and thanks for the tip in any case.
Environment
Please provide the following information about your environment:
Description
We are using a
ViroViewARCore
in a fragment. We relay all of the fragment lifecycle events to theViroViewARCore
as such:About 90% of the time when the fragment is destroyed, the app completely crashes with what looks to be a SIGSEGV.
Reproducible Demo
Crash Logs: