filament icon indicating copy to clipboard operation
filament copied to clipboard

Panic in MetalTexture: 464 And a crash occurred in FEngine::loop

Open zhanghesheng opened this issue 1 year ago • 5 comments

Switching between multiple models, such as A, B, and C, and loading new models while releasing old model data:

ResourceLoader->evictResourceData();
Scene->removeEntities(_asset->getEntities(), _asset->getEntityCount());
AssetLoader->destroyAsset(_asset);
_asset = nullptr;

When rapidly switching operations, does the CPU usage remain high, and after operating for a while, get a crash

企业微信截图_499bad68-a9a1-4373-ac88-564ede6a3a62

crash log:

Panic
in MetalTexture:464
reason: Could not create Metal texture. Out of memory?

#0	xxxxxx                            0x10484f754 _ZN5utils6TPanicINS_18PostconditionPanicEEC2EPKcS4_iNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 100
#1	xxxxxx                            0x10484f4b4 _ZN5utils18PostconditionPanicCI1NS_6TPanicIS0_EEEPKcS3_iNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEE + 12
#2	xxxxxx                            0x10484f494 _ZN5utils6TPanicINS_18PostconditionPanicEE5panicEPKcS4_iS4_z + 116
#3	xxxxxx                            0x1045c9298 _ZN8filament7backend12MetalTextureC2ERNS0_12MetalContextENS0_11SamplerTypeEhNS0_13TextureFormatEhjjjNS0_12TextureUsageENS0_14TextureSwizzleES7_S7_S7_ + 492
#4	xxxxxx                            0x1045c9754 _ZN8filament7backend12MetalTextureC1ERNS0_12MetalContextENS0_11SamplerTypeEhNS0_13TextureFormatEhjjjNS0_12TextureUsageENS0_14TextureSwizzleES7_S7_S7_ + 64
#5	xxxxxx                            0x1045b9eac _ZN8filament7backend18ConcreteDispatcherINS0_11MetalDriverEE13createTextureERNS0_6DriverEPNS0_11CommandBaseEPl + 220
#6	xxxxxx                            0x1045a21e4 _ZNSt3__110__function6__funcIZN8filament7backend13CommandStream7executeEPvE3$_0NS_9allocatorIS6_EEFvvEEclEv + 52
#7	xxxxxx                            0x1045bf484 _ZN8filament7backend11MetalDriver7executeERKNSt3__18functionIFvvEEE + 44
#8	xxxxxx                            0x1045a1f50 _ZN8filament7backend13CommandStream7executeEPv + 96
#9	xxxxxx                            0x104752c2c _ZN8filament7FEngine4loopEv + 324
#10	xxxxxx                            0x104755c5c _ZNSt3__1L14__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN8filament7FEngineEFivEPS8_EEEEEPvSD_ + 64
#11	libsystem_pthread.dylib                0x1dbef9348 _pthread_start + 116

Device: iPhone7Plus OS: iOS 15.5

zhanghesheng avatar Jul 28 '23 09:07 zhanghesheng

What does the memory graph look like? When you release the old model data, does the memory graph drop back down? I suspect there is something not being released properly that causes the device to run out of memory.

bejado avatar Jul 28 '23 18:07 bejado

If the model switching is no longer performed, memory and CPU usage will decrease. However, if model switching is rapidly and continuously performed, memory may not have enough time to decrease, and the CPU may remain in a high state. At this point, stopping the switching will also prevent the CPU from decreasing. The aforementioned issues occur when model switching is performed rapidly and continuously.

zhanghesheng avatar Aug 05 '23 02:08 zhanghesheng

Calling AssetLoader->destroyAsset(_asset) does not free GPU data (such as buffers and textures) immediately, as this is done on the separate FEngine::loop thread. So, if you're re-creating models too quickly, you can exhaust all available device memory. You can try calling engine->flushAndWait() after releasing model data to give the FEngine::loop thread a chance to free GPU data before re-loading a model.

bejado avatar Aug 07 '23 18:08 bejado

I tried calling engine->flushAndWait() after releasing the model data, but the same crash still occurs. Could you provide the proper procedure for resolving this issue on iOS?

zhanghesheng avatar Aug 09 '23 11:08 zhanghesheng

Can you modify our gltf-viewer sample to reproduce the issue? Then I can take a closer look.

bejado avatar Aug 09 '23 16:08 bejado