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

ARSceneView Compose code getting outofmemory exception #567 #568

Open
klinis opened this issue Oct 7, 2024 · 0 comments
Open

ARSceneView Compose code getting outofmemory exception #567 #568

klinis opened this issue Oct 7, 2024 · 0 comments

Comments

@klinis
Copy link

klinis commented Oct 7, 2024

When using arsceneview compose component initially it works fine but sometimes if I reopen it many times (it is hidden from compose view with if consensus) or when hiding and reopen app the application crushes with stacktrace:

Caused by: java.lang.Throwable: Explicit termination method 'release' not called at dalvik.system.CloseGuard. openWithCallSite( CloseGuard. java: 259) at dalvik.system.CloseGuard. open( CloseGuard. java: 230) at android.view.Surface. setNativeObjectLocked( Surface. java: 682) at android.view.Surface. < init> ( Surface. java: 266) at com.google.ar.infrastructure. imagesubsystem. hardwarebufferstream. AndroidHardwareBufferStreamProvider. nativeContextGetSurface( Native Method) at dai.d(PG:113) at com.google.ar.infrastructure. nativedatasource. imagesubsystem. ImageSubsystemWrapper. setGlTextureOutput( PG: 50) at com.google.ar.core.Session. nativeResume( Native Method) at com.google.ar.core.Session. resume( Session. java: 1) at io.github.sceneview. ar. arcore. ARSession. resume( ArSession. kt: 73) at io.github.sceneview. ar. ARCore. resume( ARCore. kt: 113

val engine = rememberEngine()
val view = rememberView(engine)
val renderer = rememberRenderer(engine)
val scene = rememberScene(engine)
val modelLoader = rememberModelLoader(engine)
val materialLoader = rememberMaterialLoader(engine)
val environmentLoader = rememberEnvironmentLoader(engine)
val collisionSystem = rememberCollisionSystem(view)
// var childNodes = rememberNodes()
// var arSceneView: ARSceneView? by remember { mutableStateOf(null) }
// var frame by remember { mutableStateOf<Frame?>(null) }
var childNodes by remember { mutableStateOf(emptyList()) }
// var childNodes = rememberNodes()
DisposableEffect(Unit) {
onDispose {
// CoroutineScope(Dispatchers.IO).launch {
childNodes.forEach {
// (it as AnchorNode).anchor.detach()
it.destroy()
}
childNodes = emptyList()
}
}
var frame by remember { mutableStateOf<Frame?>(null) }
I initialize all arsceneview objects and dispose properly in above given code.

    onViewUpdated = {
        if (takePhoto)
            takeScreenShot(this, coroutineScope) { bitmap ->
              ....
              
      fun takePhoto(
      view: ARSceneView,
      coroutineScope: CoroutineScope,
      onPictureSave: suspend (Bitmap) -> Unit
  ) {
  
      // Create a bitmap the size of the scene view.
      val bitmap = Bitmap.createBitmap(
          view.width, view.height,
          Bitmap.Config.ARGB_8888
      )
  
      val handlerThread = HandlerThread("PixelCopier")
      handlerThread.start()
      PixelCopy.request(view, bitmap, { copyResult: Int ->
          if (copyResult == PixelCopy.SUCCESS) {
              coroutineScope.launch {
                  try {
                      onPictureSave(bitmap)
                  } catch (e: IOException) {
                      return@launch
                  }
              }
          }
          handlerThread.quitSafely()
      }, Handler(handlerThread.looper))
  }

I only use session object to take a screenshot with the above method given in onViewUpdatedMethod. Did I miss anything? Why it has this behaviour?
Thank you very much

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