Skip to content

Conversation

sameerjj
Copy link
Contributor

@sameerjj sameerjj commented Feb 5, 2024

Problem

  • getting Crashlytics reports of ANR and user reports of app hanging when closing AR activity

Solution

  • from ArCore Session documentation:

Releases resources (a significant amount of native heap memory) used by an ARCore session.
Failure to close sessions explicitly may cause your app to run out of native memory and crash. If your app contains a single AR-enabled activity, it is recommended that you call close() from the activity's onDestroy method.
This method will take several seconds to complete. To prevent blocking the main thread, call pause() on the main thread, and then call close() on a background thread.

  • use coroutine scope to call destroy off of MainThread

Fixes #407

@sameerjj sameerjj changed the title call arcore.destroy off of main thread Fixes #407 call arcore.destroy off of main thread Feb 5, 2024
@sameerjj sameerjj changed the title Fixes #407 call arcore.destroy off of main thread call arcore.destroy off of main thread Fixes #407 Feb 5, 2024
Copy link
Contributor

@ThomasGorisse ThomasGorisse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks !

@ThomasGorisse ThomasGorisse merged commit ad8778b into SceneView:main Feb 6, 2024
@sameerjj sameerjj deleted the sameer-arcore-destroy-off-main branch February 6, 2024 19:09
@Antiglobalist
Copy link
Contributor

Antiglobalist commented Mar 6, 2024

@ThomasGorisse @sameerjj Hi !
I have updated SDK version to 2.0.4.
And i faced with NDK exception:
image

In my App flow I finish AR activity and start other one(Not AR)
I don't have any extra calls on Destroy state

I suppose it's happening cuz destroyARCore function is not thread safe inside now. And arCore.destroy() is calling twice
image
And
lifecycle?.coroutineScope is able to be not null and isActive == false at same time. And arCore.destroy() will not call

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

Successfully merging this pull request may close these issues.

ANR due to arCore.destroy() being called on the main thread
3 participants