CesiumGS / cesium-unreal

Bringing the 3D geospatial ecosystem to Unreal Engine
https://cesium.com/platform/cesium-for-unreal/
Apache License 2.0
917 stars 292 forks source link

Memory leak for cesium for unreal #552

Closed sunshineYPH closed 3 years ago

sunshineYPH commented 3 years ago

It seems like there is memory leak in cesium for unreal. If 3dtiles files is more than 8G, UE4 will crash due to huge memory after camera zoom in and zoom out.

There is a similar issue in cesium commnity: https://community.cesium.com/t/the-memory-of-cesium-for-ue4/13535

I have download cesium for unreal V1.4.1 and test. But the issue is same, which looks like the memory only increases after loading 3dtiles but never decrease.

Following is Unreal Engine 4 Crash Reporter:

LoginId:38b7a68c41645290e2aa4792ae67878a
EpicAccountId:58d55dcfccc249548eaf5aa5b45e5b76

Fatal error: [File:D:/Build/++UE4/Sync/Engine/Source/Runtime/Core/Private/GenericPlatform/GenericPlatformMemory.cpp] [Line: 197] Ran out of memory allocating 8388608 bytes with alignment 0

UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_CoreUObject
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_CesiumRuntime!applyTexture() [D:\Build\++Portal\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\CesiumForUnreal\Source\CesiumRuntime\Private\CesiumGltfComponent.cpp:1415]
UE4Editor_CesiumRuntime!loadModelGameThreadPart() [D:\Build\++Portal\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\CesiumForUnreal\Source\CesiumRuntime\Private\CesiumGltfComponent.cpp:1506]
UE4Editor_CesiumRuntime!UCesiumGltfComponent::CreateOnGameThread() [D:\Build\++Portal\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\CesiumForUnreal\Source\CesiumRuntime\Private\CesiumGltfComponent.cpp:1641]
UE4Editor_CesiumRuntime!UnrealResourcePreparer::prepareInMainThread() [D:\Build\++Portal\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\CesiumForUnreal\Source\CesiumRuntime\Private\Cesium3DTileset.cpp:450]
UE4Editor_CesiumRuntime!Cesium3DTiles::Tile::update()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTileIfNeeded()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTile()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTileIfNeeded()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTile()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTileIfNeeded()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTile()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTileIfNeeded()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTile()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTileIfNeeded()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTile()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTileIfNeeded()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTile()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTileIfNeeded()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTile()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTileIfNeeded()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTile()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::_visitTileIfNeeded()
UE4Editor_CesiumRuntime!Cesium3DTiles::Tileset::updateView()
UE4Editor_CesiumRuntime!ACesium3DTileset::Tick() [D:\Build\++Portal\Sync\LocalBuilds\PluginTemp\HostProject\Plugins\CesiumForUnreal\Source\CesiumRuntime\Private\Cesium3DTileset.cpp:987]
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_Engine
UE4Editor_UnrealEd
UE4Editor_UnrealEd
UE4Editor
UE4Editor
UE4Editor
UE4Editor
UE4Editor
kernel32
ntdll
kring commented 3 years ago

If you're running in the editor, this is probably a duplicate of #340. The Unreal Engine sadly doesn't do garbage collection by default in the Editor, nor does it have a way to free UObjects other than via garbage collection. You can enable automatic garbage collection in the Editor by setting gc.CollectGarbageEveryFrame 1 (i.e. from the Output Log window).

sunshineYPH commented 3 years ago

If you're running in the editor, this is probably a duplicate of #340. The Unreal Engine sadly doesn't do garbage collection by default in the Editor, nor does it have a way to free UObjects other than via garbage collection. You can enable automatic garbage collection in the Editor by setting gc.CollectGarbageEveryFrame 1 (i.e. from the Output Log window).

It works after enable garbage collection. The memory will increase and decrease with camera zoom in and zoom out. However there still be a crash during load more than 40G 3dtiles. Because the total memory is too huge. Even close to physical memory so that UE4 crash. But cesium-js works fine in browser with loading same files whose size is about 40G.

I'm not sure this belong to another issue or same issue in this posts. Should I create a new issue?

kring commented 3 years ago

It shouldn't matter how large the total tileset is. Cesium World Terrain, for instance, is terabytes of geometry. But if the tileset bounding volume hierarchy is not structured well, it can lead Cesium for Unreal to try to bring too much of it into memory at once. Or it could be a plain old bug. If you can share the tileset details of the tileset you're using, please do so and we can take a look. No need for a new issue, you can post it here. Thanks!

kring commented 3 years ago

Closing due to lack of follow-up. Please reopen if you can share your tileset with us for debugging.