SceneView / sceneview-android

SceneView is a 3D and AR Android Composable and View with Google Filament and ARCore. This is a Sceneform replacement in Kotlin
Apache License 2.0
847 stars 161 forks source link

app will crash when I quit activity #176

Closed xuanxuandaoren closed 1 year ago

xuanxuandaoren commented 2 years ago

11-01 17:18:20.613 1335 28986 I Camera2ClientBase: Closed Camera 0. Client was: io.github.sceneview.sample.armodelviewer (PID 12868, UID 10289) 11-01 17:18:20.614 12868 12868 I Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread. 11-01 17:18:20.615 12868 12868 W Looper : PerfMonitor doFrame : time=1ms vsyncFrame=19573743 latency=635ms procState=2 historyMsgCount=3 (msgIndex=3 wall=609ms seq=239 running=5ms runnable=1ms binder=47ms late=33ms h=android.app.ActivityThread$H w=159) 11-01 17:18:21.165 12868 12868 I native : I0000 00:00:1667294301.165340 12868 session_lite_c_api.cc:37] Deleting ArSession... 11-01 17:18:21.181 12868 12868 I native : I0000 00:00:1667294301.181094 12868 android_camera.cc:762] [Camera=1; State=CLOSED] Reset cleanly got to CLOSED state. 11-01 17:18:21.181 12868 12868 I native : I0000 00:00:1667294301.181312 12868 android_camera.cc:762] [Camera=0; State=CLOSED] Reset cleanly got to CLOSED state. 11-01 17:18:21.181 12868 12868 I native : I0000 00:00:1667294301.181779 12868 session_lite_c_api.cc:39] Deleted ArSession. 11-01 17:18:21.183 12868 12868 F libc : Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6d0 in tid 12868 (e.armodelviewer), pid 12868 (e.armodelviewer) 11-01 17:18:21.236 778 778 I tombstoned: received crash request for pid 12868 11-01 17:18:21.237 13097 13097 I crash_dump64: performing dump of process 12868 (target tid = 12868) 11-01 17:18:21.243 13097 13097 F DEBUG : pid: 12868, tid: 12868, name: e.armodelviewer >>> io.github.sceneview.sample.armodelviewer <<< 11-01 17:18:21.641 1754 3956 I ActivityManager: Process io.github.sceneview.sample.armodelviewer (pid 12868) has died: fg TOP 11-01 17:18:21.641 1754 1807 I Process : PerfMonitor : current process killing process group. PID: 12868 11-01 17:18:21.643 788 788 I Zygote : Process 12868 exited due to signal 11 (Segmentation fault) 11-01 17:18:21.647 1754 1807 I libprocessgroup: Successfully killed process cgroup uid 10289 pid 12868 in 5ms

vigit3 commented 2 years ago

Your app is running too much in man thread , try using background thread Use coroutines scope for handling your app

xuanxuandaoren commented 2 years ago

Your app is running too much in man thread , try using background thread Use coroutines scope for handling your app

I only new a activity and start MainActivity in samples ar-model-viewer。it will crash in MainActivity when BackPressed.


class TestActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)
        findViewById<Button>(R.id.btn_go_ar).setOnClickListener {
            startActivity(Intent(this,MainActivity::class.java))
        }
    }
}
vigit3 commented 2 years ago

can you upload your codes for better understanding

xuanxuandaoren commented 2 years ago

can you upload your codes for better understanding

TestActivity.java

package io.github.sceneview.sample.armodelviewer

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button

class TestActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)
        findViewById<Button>(R.id.btn_go_ar).setOnClickListener {
            startActivity(Intent(this,MainActivity::class.java))
        }
    }
}

MainActivity.java

package io.github.sceneview.sample.armodelviewer

import android.os.Bundle
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.view.isGone
import androidx.core.view.isVisible
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import io.github.sceneview.ar.ArSceneView
import io.github.sceneview.ar.arcore.LightEstimationMode
import io.github.sceneview.ar.arcore.LightEstimator
import io.github.sceneview.ar.node.ArModelNode
import io.github.sceneview.ar.node.PlacementMode
import io.github.sceneview.light.Light
import io.github.sceneview.light.LightInstance
import io.github.sceneview.math.Position
import io.github.sceneview.utils.doOnApplyWindowInsets
import io.github.sceneview.utils.setFullScreen

class MainActivity : AppCompatActivity(R.layout.activity_main) {

    lateinit var sceneView: ArSceneView
    lateinit var loadingView: View
    lateinit var placeModelButton: ExtendedFloatingActionButton
    lateinit var newModelButton: ExtendedFloatingActionButton

    private val TAG = "MainActivity"

    data class Model(
        val fileLocation: String,
        val scaleUnits: Float? = null,
        val placementMode: PlacementMode = PlacementMode.BEST_AVAILABLE,
        val applyPoseRotation: Boolean = true
    )

    val models = listOf(
        Model("models/spiderbot.glb"),
        Model(
            fileLocation = "models/zoe.glb",
            // Display the Tiger with a size of 3 m long
            scaleUnits = 0.5f,
            placementMode = PlacementMode.PLANE_HORIZONTAL,
            applyPoseRotation = false
        ),
        Model(
            fileLocation = "https://sceneview.github.io/assets/models/DamagedHelmet.glb",
            placementMode = PlacementMode.INSTANT,
            scaleUnits = 0.5f
        ),
        Model(
            fileLocation = "https://storage.googleapis.com/ar-answers-in-search-models/static/GiantPanda/model.glb",
            placementMode = PlacementMode.PLANE_HORIZONTAL,
            // Display the Tiger with a size of 1.5 m height
            scaleUnits = 1.5f
        ),
        Model(
            fileLocation = "https://sceneview.github.io/assets/models/Spoons.glb",
            placementMode = PlacementMode.PLANE_HORIZONTAL_AND_VERTICAL,
            // Keep original model size
            scaleUnits = null
        ),
        Model(
            fileLocation = "https://sceneview.github.io/assets/models/Halloween.glb",
            placementMode = PlacementMode.PLANE_HORIZONTAL,
            scaleUnits = 2.5f
        ),
    )
    var modelIndex = 0
    var modelNode: ArModelNode? = null

    var isLoading = false
        set(value) {
            field = value
            loadingView.isGone = !value
        }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setFullScreen(
            findViewById(R.id.rootView),
            fullScreen = true,
            hideSystemBars = false,
            fitsSystemWindows = false
        )

        setSupportActionBar(findViewById<Toolbar>(R.id.toolbar)?.apply {
            doOnApplyWindowInsets { systemBarsInsets ->
                (layoutParams as ViewGroup.MarginLayoutParams).topMargin = systemBarsInsets.top
            }
            title = ""
        })
        sceneView = findViewById(R.id.sceneView)

        sceneView.lightEstimationMode = LightEstimationMode.DISABLED
        loadingView = findViewById(R.id.loadingView)
        newModelButton = findViewById<ExtendedFloatingActionButton>(R.id.newModelButton).apply {
            // Add system bar margins
            val bottomMargin = (layoutParams as ViewGroup.MarginLayoutParams).bottomMargin
            doOnApplyWindowInsets { systemBarsInsets ->
                (layoutParams as ViewGroup.MarginLayoutParams).bottomMargin =
                    systemBarsInsets.bottom + bottomMargin
            }
            setOnClickListener { newModelNode() }
        }
        placeModelButton = findViewById<ExtendedFloatingActionButton>(R.id.placeModelButton).apply {
            setOnClickListener { placeModelNode() }
        }

        newModelNode()
    }

    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
        menuInflater.inflate(R.menu.activity_main, menu)
        return super.onCreateOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        item.isChecked = !item.isChecked
        modelNode?.detachAnchor()
        modelNode?.placementMode = when (item.itemId) {
            R.id.menuPlanePlacement -> PlacementMode.PLANE_HORIZONTAL_AND_VERTICAL
            R.id.menuInstantPlacement -> PlacementMode.INSTANT
            R.id.menuDepthPlacement -> PlacementMode.DEPTH
            R.id.menuBestPlacement -> PlacementMode.BEST_AVAILABLE
            else -> PlacementMode.DISABLED
        }
        return super.onOptionsItemSelected(item)
    }

    fun placeModelNode() {
        modelNode?.anchor()
        placeModelButton.isVisible = false
        sceneView.planeRenderer.isVisible = false
    }

    fun newModelNode() {
        isLoading = true
        modelNode?.takeIf { !it.isAnchored }?.let {
            sceneView.removeChild(it)
            it.destroy()
        }
        val model = models[modelIndex]
        modelIndex = (modelIndex + 1) % models.size
        modelNode = ArModelNode(model.placementMode).apply {
            applyPoseRotation = model.applyPoseRotation
            loadModelAsync(
                context = this@MainActivity,
                lifecycle = lifecycle,
                glbFileLocation = model.fileLocation,
                autoAnimate = true,
                scaleToUnits = model.scaleUnits,
                // Place the model origin at the bottom center
                centerOrigin = Position(y = -1.0f)
            ) {
                sceneView.planeRenderer.isVisible = true
                isLoading = false
            }
            onAnchorChanged = { node, _ ->
                placeModelButton.isGone = node.isAnchored
            }
            onHitResult = { node, _ ->
                placeModelButton.isGone = !node.isTracking
            }
        }
        sceneView.addChild(modelNode!!)
        // Select the model node by default (the model node is also selected on tap)
        sceneView.selectedNode = modelNode
    }
}
vigit3 commented 2 years ago

How much size is your glb file, try using small glb file and check ones again . I think this error is due to memoryexception because of large glb file is used

xuanxuandaoren commented 2 years ago

the glb size is 6.8m . I new a testactivity and start MainActivity which in samples ar-model-viewer , when I back to testactivity, it will crash A few seconds later .

kustraslawomir commented 1 year ago

Same issue on official sample. I have just added activity to open MainActivity

package io.github.sceneview.sample.armodelviewer
        findViewById<TextView>(R.id.test).setOnClickListener {
            startActivity(Intent(this, MainActivity::class.java))
        }

and on back press:

2022-11-28 11:58:58.944 12869-12869/io.github.sceneview.sample.armodelviewer A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6d0 in tid 12869 (e.armodelviewer), pid 12869 (e.armodelviewer) 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: Build fingerprint: 'samsung/beyond0lteeea/beyond0:12/SP1A.210812.016/G970FXXSGHVK1:user/release-keys' 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: Revision: '26' 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: ABI: 'arm64' 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: Processor: '7' 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: Timestamp: 2022-11-28 11:58:59.016377139+0100 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: Process uptime: 20s 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: Cmdline: io.github.sceneview.sample.armodelviewer 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: pid: 12869, tid: 12869, name: e.armodelviewer >>> io.github.sceneview.sample.armodelviewer <<< 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: uid: 10008 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6d0 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: Cause: null pointer dereference 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: x0 00000000000006c8 x1 0000000000000000 x2 0000000000000000 x3 000000006f8611d8 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: x4 0000000000000000 x5 0000000000000001 x6 0000006dd4225730 x7 0000006cf3e17000 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: x8 27e04e1bac8c2677 x9 27e04e1bac8c2677 x10 0000000000430000 x11 0000000000000005 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: x12 0000007fc6a68448 x13 0000000000000010 x14 0000006cf3618b80 x15 00000000ebad6a89 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: x16 0000006c494727d0 x17 0000007fc6a69820 x18 0000007006f36000 x19 0000000000000000 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: x20 0000000000000000 x21 0000006e6422e380 x22 0000007005ef2000 x23 0000006e6422e430 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: x24 0000006cd7b6b3d0 x25 0000006dd4226c00 x26 0000007005ef2000 x27 000000000000025d 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: x28 0000007fc6a69830 x29 0000007fc6a69830 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: lr 0000006c4946174c sp 0000007fc6a697d0 pc 0000006c49461e2c pst 0000000060000000 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: backtrace: 2022-11-28 11:58:59.313 13112-13112/? A/DEBUG: #00 pc 00000000001b7e2c /data/app/~~gCFLYH8LX2ACTY4uMmDa0w==/io.github.sceneview.sample.armodelviewer-DG6zr0VxrYqTr8snuuxHGw==/base.apk!libgltfio-jni.so (BuildId: c6c850b752925f24cdd0cecc117fd277bdf218c6) 2022-11-28 11:58:59.350 499-499/? E/tombstoned: Tombstone written to: tombstone_18 2022-11-28 11:58:59.366 515-515/? E/audit: type=1701 audit(1669633139.363:38192): auid=4294967295 uid=10008 gid=10008 ses=4294967295 subj=u:r:untrusted_app:s0:c8,c256,c512,c768 pid=12869 comm="e.armodelviewer" exe="/system/bin/app_process64" sig=11 res=1

kustraslawomir commented 1 year ago

@ThomasGorisse @xuanxuandaoren @vigit3

kustraslawomir commented 1 year ago

2022-11-28 12:01:51.809 13175-13175/io.github.sceneview.sample.armodelviewer E/native: E0000 00:00:1669633311.809612 13175 scheduler.cc:278] INTERNAL: RET_CHECK failure (thirdparty/mediapipe/framework/scheduler.cc:278) state != STATE_NOT_STARTED (0 vs. 0) Stack trace: 2022-11-28 12:01:51.809 13175-13175/io.github.sceneview.sample.armodelviewer E/native: E0000 00:00:1669633311.809660 13175 normal_detectorcpu.cc:231] Error graph->WaitUntilIdle():INTERNAL: RET_CHECK failure (thirdparty/mediapipe/framework/scheduler.cc:278) state != STATE_NOT_STARTED (0 vs. 0) === Source Location Trace: === third_party/mediapipe/framework/scheduler.cc:278 third_party/mediapipe/framework/calculator_graph.cc:845 2022-11-28 12:01:51.817 1806-3335/? E/SecHAL: nfc_data_callback: [Cmd]Received a response packet : data_sending_flag = false!! 2022-11-28 12:01:51.817 1690-3304/? E/libnfc_nci: [ERROR:nfc_ncif.cc(1457)] nfc_ncif_proc_deactivate - evt_data.deactivate.reason 0, nfc_cb.deact_reason = 0 2022-11-28 12:01:51.817 1806-1806/? E/SecHAL: nfc_hal_write: [Cmd]Send EVT data_sending_flag = true, return size=18!! 2022-11-28 12:01:51.826 1806-3335/? E/SecHAL: nfc_data_callback: [Cmd]Received a response packet : data_sending_flag = false!! 2022-11-28 12:01:52.060 430-430/? E/vold: getUsedF2fsFileNode -> Cannot Get Used FileNode Number (errno=25 Inappropriate ioctl for device) 2022-11-28 12:01:52.251 13175-13175/io.github.sceneview.sample.armodelviewer A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6d0 in tid 13175 (e.armodelviewer), pid 13175 (e.armodelviewer) 2022-11-28 12:01:52.591 13391-13391/? A/DEBUG:

jamesC21 commented 1 year ago

I'm running into the same issue with SEGV_MAPERR. I have a simple way to repo though which is simply enabling layout inspector when running samples/model-viewer. Crash every time with 0.9.0. With the latest, running samples/model-viewer directly in the repo, it also crashes when enabling layout inspector this time with ending with this. at io.github.sceneview.nodes.Node.destroy(Node.kt:262) at io.github.sceneview.nodes.CameraNode.destroy(CameraNode.kt:53) at io.github.sceneview.SceneView.destroy(SceneView.kt:693) at io.github.sceneview.SceneView$setLifecycle$3.invoke(SceneView.kt:718) at io.github.sceneview.SceneView$setLifecycle$3.invoke(SceneView.kt:718) E/AndroidRuntime: at com.gorisse.thomas.lifecycle.LifecycleKt$observe$1.onDestroy(Lifecycle.kt:164) at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:51) at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:360) at androidx.lifecycle.LifecycleRegistry.backwardPass(LifecycleRegistry.java:290) at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:308) at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:151) at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134) at androidx.fragment.app.Fragment.performDestroy(Fragment.java:3352) at androidx.fragment.app.FragmentStateManager.destroy(FragmentStateManager.java:781) at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:335) at androidx.fragment.app.SpecialEffectsController$FragmentStateManagerOperation.complete(SpecialEffectsController.java:771) at androidx.fragment.app.SpecialEffectsController$Operation.cancel(SpecialEffectsController.java:615) at androidx.fragment.app.SpecialEffectsController.forceCompleteAllOperations(SpecialEffectsController.java:350) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2980) at androidx.fragment.app.FragmentManager.dispatchDestroy(FragmentManager.java:2931) at androidx.fragment.app.FragmentController.dispatchDestroy(FragmentController.java:346) at androidx.fragment.app.FragmentActivity.onDestroy(FragmentActivity.java:259) at androidx.appcompat.app.AppCompatActivity.onDestroy(AppCompatActivity.java:280) at android.app.Activity.performDestroy(Activity.java:8319) at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1376) at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5413) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5459) at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:5759) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:5675) at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:71) at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ClientTransactionHandler.executeTransaction(ClientTransactionHandler.java:62) at android.app.ActivityThread.handleRelaunchActivityLocally(ActivityThread.java:5742) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2262) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7842) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

Please help with a fix (even if I can just do it locally that would be much appreciated).
I adding logging in MainFragment onDestroyView() override and it dies After super.onDestroyView()

sameerjj commented 1 year ago

I'm getting a similar issue once integrating the library with my project. my GLB file is only 137KB. It happens for me every time when leaving the Activity

13:15:47.862  W  W0000 00:00:1670868947.862296   23919 anchor_manager.cc:69] Remove/detach called on an anchor that was already removed/detached.
13:15:47.862  I  I0000 00:00:1670868947.862392   23919 cloud_anchor_manager.cc:477] Anchor Hosting is not configured.
13:15:47.862  A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6d0 in tid 23919 (ozerapp.balcony), pid 23919 (ozerapp.balcony)
13:15:48.366  A  Cmdline: com.app.vioozerapp.balcony
13:15:48.366  A  pid: 23919, tid: 23919, name: ozerapp.balcony  >>> com.app.vioozerapp.balcony <<<
13:15:48.366  A        #00 pc 00000000001b7e2c  /data/app/~~Dt03PIVTh9Prgz-ypOBrsA==/com.app.vioozerapp.balcony-HgAZL4v2bps1HCiNRnPfgA==/lib/arm64/libgltfio-jni.so (BuildId: c6c850b752925f24cdd0cecc117fd277bdf218c6)

I wish the logs were more helpful :(. Here are some logs filtered by level:error, the no point hits seem pretty standard for the library but it's everything else that starts to get a bit funky:


13:17:05.104  E  E0000 00:00:1670869025.104371   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:05.204  E  E0000 00:00:1670869025.204381   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:05.309  E  E0000 00:00:1670869025.309119   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:05.404  E  E0000 00:00:1670869025.404200   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:05.506  E  E0000 00:00:1670869025.506266   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:05.603  E  E0000 00:00:1670869025.603639   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:05.671  E  E0000 00:00:1670869025.671038   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:06.483  E  E0000 00:00:1670869026.483310   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:06.641  E  E0000 00:00:1670869026.641128   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:06.699  E  E0000 00:00:1670869026.699714   24850 hit_test.cc:428] INTERNAL: No point hit.
13:17:06.894  E  E0000 00:00:1670869026.894100   24850 scheduler.cc:278] INTERNAL: RET_CHECK failure (third_party/mediapipe/framework/scheduler.cc:278) state_ != STATE_NOT_STARTED (0 vs. 0) 
                 Stack trace:
13:17:06.894  E  E0000 00:00:1670869026.894135   24850 normal_detector_cpu.cc:233] Error graph_->WaitUntilIdle():INTERNAL: RET_CHECK failure (third_party/mediapipe/framework/scheduler.cc:278) state_ != STATE_NOT_STARTED (0 vs. 0) 
                 === Source Location Trace: === 
                 third_party/mediapipe/framework/scheduler.cc:278
                 third_party/mediapipe/framework/calculator_graph.cc:845
13:17:07.427  A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6d0 in tid 24850 (ozerapp.balcony), pid 24850 (ozerapp.balcony)
13:17:08.028  A  Cmdline: com.app.vioozerapp.balcony
13:17:08.028  A  pid: 24850, tid: 24850, name: ozerapp.balcony  >>> com.app.vioozerapp.balcony <<<
13:17:08.028  A        #00 pc 00000000001b7e2c  /data/app/~~Dt03PIVTh9Prgz-ypOBrsA==/com.app.vioozerapp.balcony-HgAZL4v2bps1HCiNRnPfgA==/lib/arm64/libgltfio-jni.so (BuildId: c6c850b752925f24cdd0cecc117fd277bdf218c6)
sameerjj commented 1 year ago

I got some more logs that were a bit more helpful. I was able to reproduce on the sample app sample-ar-cursor-placement with an introduced additional dummy launcher activity with a button that launches the provided Activity

20:06:42.977  E  E0000 00:00:1670893602.977739   28618 scheduler.cc:278] INTERNAL: RET_CHECK failure (third_party/mediapipe/framework/scheduler.cc:278) state_ != STATE_NOT_STARTED (0 vs. 0) 
                 Stack trace:
20:06:42.977  E  E0000 00:00:1670893602.977776   28618 normal_detector_cpu.cc:233] Error graph_->WaitUntilIdle():INTERNAL: RET_CHECK failure (third_party/mediapipe/framework/scheduler.cc:278) state_ != STATE_NOT_STARTED (0 vs. 0) 
                 === Source Location Trace: === 
                 third_party/mediapipe/framework/scheduler.cc:278
                 third_party/mediapipe/framework/calculator_graph.cc:845
20:06:43.556  E  in destroy:959
                 reason: destroying material "base_lit_opaque" but 8 instances still alive
20:06:43.556  E  
20:06:43.669  A  Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 28618 (y.direct_relief), pid 28618 (y.direct_relief)
20:06:44.284  A  Cmdline: com.app.balcony.direct_relief
20:06:44.284  A  pid: 28618, tid: 28618, name: y.direct_relief  >>> com.app.balcony.direct_relief <<<
20:06:44.284  A        #00 pc 00000000000cbca0  /data/app/~~n6dZR_hsLeFIyUwdXVKWTQ==/com.app.balcony.direct_relief-mMLFF8DeW3UYAwuxMHnHQA==/base.apk!libfilament-jni.so (BuildId: 566f8cb854d0326e1c1af97cea1dd2f3831c599b)
ryust commented 1 year ago

I'm experiencing the same Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) error when exiting back to a parent activity. The GLB is only 15k in size.

ghost commented 1 year ago

The same happens to me. It's not related to the Activity but to the lifeCycle passed to the constructor of the Nodes. If you're passing activity lifecycle, it will crash when the activity is destroyed. If you pass Fragment lifecycle, then it will crash when the fragment is destroyed. If you pass the viewLifecycle of the fragment, it will crash when the view of the fragment is destroyed. In my project, I'm using a single activity with fragments and navigation components. When I navigate away from the AR fragment, it crashes. It can be reproduced with the sample app, for ex. like this:

sameerjj commented 1 year ago

heads up that very possible this will be fixed by https://github.com/SceneView/sceneview-android/pull/150. Not sure though, just heads up in case anyone is in dire need.

UnicornJin commented 1 year ago

Also facing the similar problem. I'm using the sceneView in something like bottom navigation Fragment. When I switch the fragment from the one with sceneView to another one. The app will crash and seems there's something wrong with the destroy process.

jklitsie commented 1 year ago

We also had this problem on back navigation. We got it working by replacing the lifecycle = lifecycle with :

 loadModelAsync(
                context = requireContext(),
                lifecycle = requireActivity().lifecycle,
                glbFileLocation = "models/spiderbot.glb"
            )

But this will only work if you are running a single activity type in your application, I would see this crashing when you would navigate back towards a activity that hasn't been initialized.

ryust commented 1 year ago

None of the above has helped with the crashes. Has anyone gotten this to work doing an exit of AppCompatActivity with a SceneView in it?

ghost commented 1 year ago

150

This will "mute" your crash because your app will be already in the background when the crash happens, so you won't see it :) It's definitely an issue with the destroy process, I can't imagine any workaround for it.

ryust commented 1 year ago

Any more progress on this issue?

AdrienBotrel commented 1 year ago

For the moment, the only way I found to don't have this issue is to have only one activity and several fragment and to don't destroy the fragment containing the arSceneView when I want to use an other fragment. So so fragment with the arSceneview continue to consume some ressources in the background but at least the app doesn't crash

ryust commented 1 year ago

I've done something similar by putting the ArSceneView in a dialog that I hide instead of dismiss/cancel, but the camera stays on after returning back to the parent activity. This can look suspicious to the user when the camera indicator shows it's active. How did you handle that?

AdrienBotrel commented 1 year ago

I'm using this function when I press the back button: `private fun backToMainMenu(){ val fragment : Fragment = MainMenuFragment()

    val manager : FragmentManager = supportFragmentManager

    // Begin the fragment transition using support fragment manager
    val transaction: FragmentTransaction = manager.beginTransaction()

    // Replace the fragment on container
    transaction.replace(R.id.containerFragment, fragment)

    // Finishing the transition
    transaction.commit()
}`

With this code, the fragment where I have my arSceneView is Stopped but not Destroyed. So the camera is closed (normally) and the app doesn't crash. But if this parent activity is closed, the fragment is also closed and the app crash. So the issue is not solved but only pushed back

ThomasGorisse commented 1 year ago

Fixed in v0.9.2

m-paunovic-vegait commented 1 year ago

This still seems to be an issue in v0.9.2.

ThomasGorisse commented 1 year ago

@m-paunovic-vegait Are you sure it's the same issue? Can you send your logs?

m-paunovic-vegait commented 1 year ago

I'm seeing:

D/ViewRootImpl@956c92e[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 0 1
D/InputMethodManager: prepareNavigationBarInfo() DecorView@22d2b14[MainActivity]
D/InputMethodManager: getNavigationBarColor() 0
D/InputTransport: Input channel destroyed: fd=148
D/ViewRootImpl@e223100[ViewRenderableWindow]: dispatchDetachedFromWindow
D/ViewRootImpl@e223100[ViewRenderableWindow]: Surface release. android.view.ViewRootImpl.doDie:7976 android.view.ViewRootImpl$ViewRootHandler.handleMessage:4967 android.os.Handler.dispatchMessage:106 android.os.Looper.loop:214 android.app.ActivityThread.main:7050 java.lang.reflect.Method.invoke:-2 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run:494 com.android.internal.os.ZygoteInit.main:965 
D/InputTransport: Input channel destroyed: fd=145
D/SurfaceView: onWindowVisibilityChanged(8) false io.github.sceneview.ar.ArSceneView{fc8c7f1 V.E...... ........ 0,0-1080,2220 #7f08014d app:id/sceneView} of ViewRootImpl@956c92e[MainActivity]
D/SurfaceView: show() Surface(name=SurfaceView - io.github.sceneview.sample.armodelviewer/io.github.sceneview.sample.armodelviewer.MainActivity@fc8c7f1@0[2750])/@0xc7b626f io.github.sceneview.ar.ArSceneView{fc8c7f1 V.E...... ........ 0,0-1080,2220 #7f08014d app:id/sceneView}
D/SurfaceView: surfaceDestroyed callback.size 1 #2 io.github.sceneview.ar.ArSceneView{fc8c7f1 V.E...... ........ 0,0-1080,2220 #7f08014d app:id/sceneView}
W/libEGL: EGLNativeWindowType 0x7a945fd010 disconnect failed
D/SurfaceView: destroy() Surface(name=SurfaceView - io.github.sceneview.sample.armodelviewer/io.github.sceneview.sample.armodelviewer.MainActivity@fc8c7f1@0[2750])/@0xc7b626f io.github.sceneview.ar.ArSceneView{fc8c7f1 V.E...... ........ 0,0-1080,2220 #7f08014d app:id/sceneView}
W/libEGL: EGLNativeWindowType 0x7a945fc010 disconnect failed
D/OpenGLRenderer: eglDestroySurface = 0x7a94324180, 0x7a945fc000
D/ViewRootImpl@956c92e[MainActivity]: Relayout returned: old=[0,0][1080,2220] new=[0,0][1080,2220] result=0x5 surface={valid=false 0} changed=true
D/ViewRootImpl@956c92e[MainActivity]: setWindowStopped(true) old=false
D/SurfaceView: windowStopped(true) false io.github.sceneview.ar.ArSceneView{fc8c7f1 V.E...... ........ 0,0-1080,2220 #7f08014d app:id/sceneView} of ViewRootImpl@956c92e[MainActivity]
D/ViewRootImpl@956c92e[MainActivity]: Surface release. android.view.WindowManagerGlobal.setStoppedState:669 android.app.Activity.performStop:7650 android.app.ActivityThread.callActivityOnStop:4379 android.app.ActivityThread.performStopActivityInner:4357 android.app.ActivityThread.handleStopActivity:4432 android.app.servertransaction.TransactionExecutor.performLifecycleSequence:192 android.app.servertransaction.TransactionExecutor.cycleToPath:165 android.app.servertransaction.TransactionExecutor.executeLifecycleState:142 
E/Filament: in destroy:959
    reason: destroying material "View" but 2 instances still alive
E/Filament: 
I/native: I0000 00:00:1674046958.175011    2750 session_lite_c_api.cc:37] Deleting ArSession...
I/native: I0000 00:00:1674046958.229749    2949 jni_util.cc:91] Exiting thread. Detach thread.
W/native: W0000 00:00:1674046958.239855    2750 data_manager.cc:433] VIO filter reset a total of 1 times.
I/native: I0000 00:00:1674046958.263436    2750 session_lite_c_api.cc:39] Deleted ArSession.
W/e.armodelviewe: 0xebadde09 skipped times: 0
A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x6d0 in tid 2750 (e.armodelviewer), pid 2750 (e.armodelviewer)
Disconnected from the target VM, address: 'localhost:56353', transport: 'socket'
ThomasGorisse commented 1 year ago

@m-paunovic-vegait Can you make a test with v0.9.3

ryust commented 1 year ago

I still get the "Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)" error when exiting a fragment with ArSceneView back to the calling activity. Both 0.9.2 and 0.9.3 fail.

Is there a test case that was used to valid the error as resolved? Maybe looking at the code I could do something similar.

ThomasGorisse commented 1 year ago

It's quite hard for me to debug since not all your logs show the same thing. Since it might depends on your usage (Flutter, multiple activities, self destroy calls), could you please all help debugging the destroy call that is throwing the crash?

The goal is to F7 on Filament destroys so we find the one that is throwing a runtime exception (Double destroy, Instance not released before class,...)

Thanks

ThomasGorisse commented 1 year ago

Please check v0.9.4

m-paunovic-vegait commented 1 year ago

v0.9.4 no longer crashes for me.

ryust commented 1 year ago

0.9.4 also works for me. Thanks for getting this issue resolved!

ThomasGorisse commented 1 year ago

And good thing is it doesn't skip any Filament destroy since model asset data releasing must be done at the loading time (already the case) and not on the destroy. We'll bring back some commented destroys we though responsible of this. Let us know if any destroy issue come back on next versions.

vedprakashwagh commented 1 year ago

@ThomasGorisse The crashes are back in 0.9.5 version whenever I go back. I had to search for this issue in order to find the reason, but reverting back to 0.9.4 fixed it for me.

Here's the error -

`Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x110 in tid 7304 (myappid), pid 7304 (myappid)

pid: 7304, tid: 7304, name: myappid >>> myappid <<< 2023-02-02 18:47:21.334 7544-7544 DEBUG crash_dump64 A #00 pc 00000000001ce494 /data/app/~~ndZOfziN33j0aLA9-J7bcw==/myappid-r_D_W4qeV5gz75r50UHj0Q==/base.apk!libgltfio-jni.so (filament::gltfio::FilamentAsset::getAssetInstanceCount() const+0) (BuildId: 1f80989e9281f45e9e1be04a9226cfdef6f2338b) `

ThomasGorisse commented 1 year ago

Sorry about that, 0.9.5 uses the latest Filament version that completely renew the model asset and instances usage. Could you please fix this destroy issue @vedprakashwagh ?

vedprakashwagh commented 1 year ago

@ThomasGorisse I'm sorry but I actually have zero experience about this library or AR in general since I just started exploring this yesterday. I'm afraid I might inadvertently make things worse, haha. But I'll try to fix it if possible whenever I get time.

sameerjj commented 1 year ago

Hi @ThomasGorisse, I'm quite out of my wheelhouse on this one but trying my best to help fix this issue on 0.9.5.

Essentially, the destroy that crashes the app is the first call to asset.destroy() after filament.destroy() has already been called. The _assetLoader is set to null, so it is reinstantiated from the call to Filament.assetLoader in asset.destroy(), that works fine, but the subsequent call to AssetLoader.nDestroyAsset(mNativeObject, asset.getNativeObject()); seems to crash the app.

https://github.com/sameerjj/sceneview-android/tree/sameer-debug-destroy-crash

I have a forked branch here that has a MainActivity in sample/ar-cursor-placement which allows for easy reproduction of the issue.

Hoping this provides some help!

ThomasGorisse commented 1 year ago

Hi @sameerjj Nice investigation !!! Could you make a Pull Request with it? You should be able to directly create from your fork. Thanks

sameerjj commented 1 year ago

Thanks @ThomasGorisse, done :)

james-wemoms commented 1 year ago

Hi everyone ! Is there any news regarding this issue as this crash makes this library unusable for me :( ?