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.35k stars 1.84k forks source link

Android UI not responding when loading larger GLB model #7956

Open mbalajee opened 2 days ago

mbalajee commented 2 days ago

⚠️ Issues not using this template will be systematically closed.

Describe the bug When loading larger models (over 8K entities) ModelViewer#loadModelGlb blocks the UI. Calling this function in a different thread results in This thread has not been adopted when executing ResourceLoader::Impl::computeTangents

Engine has been created from main thread so as per the below comment in Engine.cpp,

    // we're assuming we're on the main thread here.
    // (it may not be the case)
    mJobSystem.adopt();

only the thread from which the Engine is created will be adopted by the JobSystem which eventually blocks the UI when loading larger model

To Reproduce Steps to reproduce the behavior: Loading a larger model hangs the entire UI, can't exit out of the screen

Expected behavior UI should not be blocked

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Sorry couldn't attach the glb file as it is confidential

mbalajee commented 2 days ago

UI is not blocked when I create the ModelViewer instance (& so the Engine instance) in Executors.newSingleThreadExecutor() & call modelViewer.render from the same executor. Is this the right way to unblock UI or is there a downside in creating ModelViewer in a non-main thread?

mbalajee commented 1 day ago

Oh when I back out of the screen I get this error,

Precondition
in shutdown:444
reason: Engine::shutdown() called from the wrong thread!

because ModelViewer destroys the view in addOnAttachStateChangeListener so I guess it is not as straightforward as operating modelViewer on a non-ui thread

@romainguy would you recommend maintaining a copy of ModelViewer ?