google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.74k stars 1.88k forks source link

Android app crash | A Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x711e57a2b4 in tid 24900 (FEngine::loop) #7083

Closed ihsanulhaq89 closed 1 year ago

ihsanulhaq89 commented 1 year ago

Description: Android app crashes while trying to load a .glb file.

Steps to reproduce the behavior:

class SimpleActivity : AppCompatActivity() { private lateinit var binding: SimpleLayoutBinding

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    binding = SimpleLayoutBinding.inflate(layoutInflater)
    setContentView(binding.root)
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
    binding.model.loadGlb(fileName = "45085ebd-4f17-4bbd-8128-8943cf02b913-body.glb")
}

override fun onDestroy() {
    binding.model.onDestroy()
    super.onDestroy()
}

override fun onResume() {
    super.onResume()
    binding.model.onResume()
}

override fun onPause() {
    super.onPause()
    binding.model.onPause()
}

}

R.layout.simple_layout:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/simple_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <com.android.app.widgets.Model3DViewNoTouch android:id="@+id/model" android:layout_width="match_parent" android:layout_height="match_parent" />

import android.annotation.SuppressLint import android.content.Context import android.util.AttributeSet import android.view.Choreographer import android.view.SurfaceView import com.google.android.filament.Skybox import com.google.android.filament.utils.KTX1Loader import com.google.android.filament.utils.ModelViewer import com.google.android.filament.utils.Utils import java.io.File import java.io.FileInputStream import java.nio.ByteBuffer

class Model3DViewNoTouch @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 ) : SurfaceView(context, attrs, defStyleAttr, defStyleRes) {

init {
    Utils.init()
    loadEntity()
    setSurfaceView()
}

private lateinit var choreographer: Choreographer
private lateinit var modelViewer: ModelViewer

private fun loadEntity() {
    choreographer = Choreographer.getInstance()
}

@SuppressLint("ClickableViewAccessibility")
private fun setSurfaceView() {
    val mSurfaceView: SurfaceView = this
    modelViewer = ModelViewer(mSurfaceView)
    mSurfaceView.setOnTouchListener { _, _ ->
        false
    }

    // Skybox and background color
    // without this part the scene will appear broken
    modelViewer.scene.skybox = Skybox.Builder().build(modelViewer.engine)
    modelViewer.scene.skybox?.setColor(0.0f, 0.0f, 0.0f, 1.0f) // black color
}

fun loadGlb(context: Context = getContext(), fileName: String) {
    val buffer = readFile("${context.filesDir.absolutePath}/Avatar/$fileName")
    modelViewer.apply {
        loadModelGlb(buffer)
        transformToUnitCube()
    }
    loadIndirectLight(context)
}

fun loadGlb(context: Context = getContext(), file: File) {
    val buffer = readFile(file.absolutePath)
    modelViewer.apply {
        loadModelGlb(buffer)
        transformToUnitCube()
    }
    loadIndirectLight(context)
}

private fun loadIndirectLight(context: Context, ibl: String = "venetian_crossroads_2k") {
    // Create the indirect light source and add it to the scene.
    val buffer = readAsset(context, "environments/venetian_crossroads_2k/${ibl}_ibl.ktx")
    KTX1Loader.createIndirectLight(modelViewer.engine, buffer).apply {
        intensity = 50_000f
        modelViewer.scene.indirectLight = this
    }
}

private fun readAsset(context: Context, assetName: String): ByteBuffer {
    val input = context.assets.open(assetName)
    val bytes = ByteArray(input.available())
    input.read(bytes)
    return ByteBuffer.wrap(bytes)
}
private fun readFile(filePath: String): ByteBuffer {
    val input = FileInputStream(File(filePath))
    val bytes = ByteArray(input.available())
    input.read(bytes)
    return ByteBuffer.wrap(bytes)
}

private val frameCallback = object : Choreographer.FrameCallback {
    private val startTime = System.nanoTime()
    override fun doFrame(currentTime: Long) {
        val seconds = (currentTime - startTime).toDouble() / 1_000_000_000
        choreographer.postFrameCallback(this)
        modelViewer.animator?.apply {
            if (animationCount > 0) {
                applyAnimation(0, seconds.toFloat())
            }
            updateBoneMatrices()
        }
        modelViewer.render(currentTime)
    }
}

fun onResume() {
    choreographer.postFrameCallback(frameCallback)
}

fun onPause() {
    choreographer.removeFrameCallback(frameCallback)
}

fun onDestroy() {
    choreographer.removeFrameCallback(frameCallback)
}

}

Logs:

2023-08-17 12:50:49.058 24830-24900 libc com.android.app.dev A Fatal signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x711e57a2b4 in tid 24900 (FEngine::loop), pid 24830 (ic.app.dev) 2023-08-17 12:50:49.352 24830-24880 ion com.android.app.dev E ioctl c0044901 failed with code -1: Invalid argument Cmdline: com.android.app.dev 2023-08-17 12:50:49.787 24905-24905 DEBUG pid-24905 A pid: 24830, tid: 24900, name: FEngine::loop >>> com.android.app.dev <<< 2023-08-17 12:50:49.788 24905-24905 DEBUG pid-24905 A #09 pc 000000000013f9a0 /data/app/~~erYd9kYIuilB2M0Dh6UXhA==/com.android.app.dev-uoZ__uNIet9KRvMRHBGA9A==/lib/arm64/libfilament-jni.so (BuildId: b9f64c874540f69982ccb101cd9bc5851f534026)

Device: Samsung Galaxy A03 Model: SM-A037F/DS OS: Android 12

pixelflinger commented 1 year ago

could we get the complete crashlog please?

romainguy commented 1 year ago

And can you share your glb as well so we can try to reproduce the issue?

ihsanulhaq89 commented 1 year ago

https://drive.google.com/file/d/1MSQ6gjGS_bsva1wUH58jp2LszSs2lpVM/view?usp=sharing

this is the path to glb.

ihsanulhaq89 commented 1 year ago

unfortunately. the above are the complete logs. the issue is reproducible with a 100% occurrence.

I have tried to run the code again - but found no more errors or exceptions. If found, i shall share immediately.

ihsanulhaq89 commented 1 year ago

requesting an update on the above please.

ihsanulhaq89 commented 1 year ago

requesting an update on the above once again plz.. let me know if i can provide anything else.

ihsanulhaq89 commented 1 year ago

@pixelflinger @romainguy any updates on this? requesting assistance plz.

ihsanulhaq89 commented 1 year ago

@pixelflinger @romainguy this is getting critical for me.. any leads yet? any help is appreciated.

pixelflinger commented 1 year ago

We don't have a Samsung Galaxy A03 to test on, and the problem doesn't happen on my device. There is not enough information in the crash log given to take any action, unfortunately.

I still would like the full log -- it should contain register dump and a longer stack trace.

You could also try to build a debug version of filament, it might give more information about the problem.

ihsanulhaq89 commented 1 year ago

@pixelflinger thanks for your response. I was able to acquire the logs.

    2023-09-05 14:07:10.446   837-912   hwcomposer              and...graphics.composer@2.1-service  I  [HWCDisplay] [Display_0 (type:1)] fps:59.688622,dur:1005.22,max:17.84,min:16.01
    2023-09-05 14:07:10.477 31070-31070 DEBUG                   pid-31070                            A  *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    2023-09-05 14:07:10.477 31070-31070 DEBUG                   pid-31070                            A  Build fingerprint: 'samsung/a03snnxx/a03s:12/SP1A.210812.016/A037FXXU1BVFB:user/release-keys'
    2023-09-05 14:07:10.477 31070-31070 DEBUG                   pid-31070                            A  Revision: '0'
    2023-09-05 14:07:10.477 31070-31070 DEBUG                   pid-31070                            A  ABI: 'arm64'
    2023-09-05 14:07:10.477 31070-31070 DEBUG                   pid-31070                            A  Processor: '7'
    2023-09-05 14:07:10.477 31070-31070 DEBUG                   pid-31070                            A  Timestamp: 2023-09-05 14:07:09.327594376+0400
    2023-09-05 14:07:10.477 31070-31070 DEBUG                   pid-31070                            A  Process uptime: 15s
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A  Cmdline: com.android.app.staging
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A  pid: 30787, tid: 31057, name: FEngine::loop  >>> com.android.app.staging <<<
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A  uid: 10276
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A  signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x74132932b4
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A      x0  0000000000040000  x1  b4000073f3254410  x2  b4000073bcec8fd0  x3  0000000000000000
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A      x4  0000000000000000  x5  00000000ffffffff  x6  0000000000000000  x7  0000000000000000
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A      x8  b4000073f44ea400  x9  0000000007ffffff  x10 00000000ffffffff  x11 b400007413291ffc
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A      x12 0000000000000001  x13 b4000073bd27b390  x14 0000000000000000  x15 0000000000000001
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A      x16 b4000073f3254430  x17 0000000000000001  x18 00000073a8864000  x19 b4000073f3292000
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A      x20 b4000073bd27b490  x21 b4000073f3254410  x22 00000000ffffffff  x23 b4000073f49b6a14
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A      x24 b4000073bd27b210  x25 0000000000000002  x26 b4000073f49b6a64  x27 b4000073f49b6a10
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A      x28 0000000000000001  x29 00000073f01450c0
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A      lr  00000074442a58e0  sp  00000073f01448e0  pc  00000074442a5a64  pst 0000000080000000
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A  backtrace:
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A        #00 pc 0000000000131a64  /vendor/lib64/libusc.so (BuildId: 50b51f3c9fe9d6c0b697f3fee79e3db6)
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A        #01 pc 000000000014e0fc  /vendor/lib64/libusc.so (BuildId: 50b51f3c9fe9d6c0b697f3fee79e3db6)
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A        #02 pc 00000000001458b4  /vendor/lib64/libusc.so (BuildId: 50b51f3c9fe9d6c0b697f3fee79e3db6)
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A        #03 pc 0000000000138660  /vendor/lib64/libusc.so (BuildId: 50b51f3c9fe9d6c0b697f3fee79e3db6)
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A        #04 pc 0000000000049a38  /vendor/lib64/libusc.so (PVRUniFlexCompileToHw+19940) (BuildId: 50b51f3c9fe9d6c0b697f3fee79e3db6)
    2023-09-05 14:07:10.478 31070-31070 DEBUG                   pid-31070                            A        #05 pc 000000000010b60c  /vendor/lib64/libglslcompiler.so (GLSLCompileToUniflex+17396) (BuildId: 9c06f5a2bfc1e562b5fce39792d74122)
    2023-09-05 14:07:10.479 31070-31070 DEBUG                   pid-31070                            A        #06 pc 0000000000111278  /vendor/lib64/egl/libGLESv2_mtk.so (BuildId: e4df3d68e05df74645dcb8286d896e8b)
    2023-09-05 14:07:10.479 31070-31070 DEBUG                   pid-31070                            A        #07 pc 0000000000111e34  /vendor/lib64/egl/libGLESv2_mtk.so (BuildId: e4df3d68e05df74645dcb8286d896e8b)
    2023-09-05 14:07:10.479 31070-31070 DEBUG                   pid-31070                            A        #08 pc 000000000011f488  /vendor/lib64/egl/libGLESv2_mtk.so (glCompileShader+232) (BuildId: e4df3d68e05df74645dcb8286d896e8b)
    2023-09-05 14:07:10.479 31070-31070 DEBUG                   pid-31070                            A        #09 pc 000000000012f748  /data/app/~~TmEQCUE90CvARrbD39YFxg==/com.android.app.staging-8YtUMjcEce8gtWHRZtii2A==/lib/arm64/libfilament-jni.so (BuildId: b0826f2754a95429ecf9e89c83684e184d383cff)
    2023-09-05 14:07:10.551   545-545   tombstoned              tombstoned                           E  Tombstone written to: tombstone_24
    2023-09-05 14:07:10.553  1435-31118 DropBoxManagerService   system_server                        I  add tag=data_app_native_crash isTagEnabled=true flags=0x2
    2023-09-05 14:07:10.554  1435-31117 ActivityManager         system_server                        W  crash : com.android.app.staging,10276
    2023-09-05 14:07:10.555  1435-31117 ContextImpl             system_server                        W  Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1242 com.android.server.am.AppErrors.crashApplicationInner:723 com.android.server.am.AppErrors.crashApplication:584 com.android.server.am.ActivityManagerService.handleApplicationCrashInner:9735 com.android.server.am.NativeCrashListener$NativeCrashReporter.run:119
    2023-09-05 14:07:10.556  1435-31117 ActivityTaskManager     system_server                        W    Force finishing activity com.android.app.staging/com.android.app.ui.main.MainActivity
    2023-09-05 14:07:10.557  1435-31117 WindowManager           system_server                        W  Prepare app transition: mNextAppTransitionRequests=[TRANSIT_CLOSE], mNextAppTransitionFlags=TRANSIT_FLAG_APP_CRASHED, displayId: 0 Callers=com.android.server.wm.DisplayContent.prepareAppTransition:6369 com.android.server.wm.Task.finishTopCrashedActivityLocked:8844 com.android.server.wm.RootWindowContainer.lambda$finishTopCrashedActivities$20:2781 com.android.server.wm.RootWindowContainer$$ExternalSyntheticLambda30.accept:10 com.android.server.wm.Task.forAllTasks:5157
    2023-09-05 14:07:10.558  1435-1558  BootReceiver            system_server                        I  Copying /data/tombstones/tombstone_24 to DropBox (SYSTEM_TOMBSTONE)
    2023-09-05 14:07:10.558  1435-31117 WindowManager           system_server                        W  Prepare app transition: mNextAppTransitionRequests=[TRANSIT_CLOSE, TRANSIT_CLOSE], mNextAppTransitionFlags=TRANSIT_FLAG_APP_CRASHED, displayId: 0 Callers=com.android.server.wm.DisplayContent.prepareAppTransition:6369 com.android.server.wm.DisplayContent.requestTransitionAndLegacyPrepare:6384 com.android.server.wm.Task.finishTopCrashedActivityLocked:8845 com.android.server.wm.RootWindowContainer.lambda$finishTopCrashedActivities$20:2781 com.android.server.wm.RootWindowContainer$$ExternalSyntheticLambda30.accept:10
    2023-09-05 14:07:10.559  1435-1558  DropBoxManagerService   system_server                        I  add tag=SYSTEM_TOMBSTONE isTagEnabled=true flags=0x6
    2023-09-05 14:07:10.560  1435-31117 InputDispatcher         system_server                        D  Focused application set to (0): e82487
ihsanulhaq89 commented 1 year ago

@pixelflinger was this log any helpful?

ihsanulhaq89 commented 1 year ago

any updates here?

pixelflinger commented 1 year ago

Oh that's the PowerVR crash. It's a duplicate of #5118. This should have been fixed by #7051. Are you sure you have that change?

pixelflinger commented 1 year ago

duplicate of https://github.com/google/filament/issues/5118