Terrain3D icon indicating copy to clipboard operation
Terrain3D copied to clipboard

Enabling collision increases memory consumption each time the scene is reloaded.

Open easjfpjpasoepa opened this issue 1 year ago • 5 comments

Terrain3D version

v0.9.1-beta

System information

Godot_v4.2.2-stable Vulkan Forward+

Is the issue reproducable in the demo?

Yes

Issue description

Each time I reload a scene with terrain placed, memory consumption increases. Disabling collisions does not cause this problem. The same problem occurred when exporting to an executable file. https://github.com/TokisanGames/Terrain3D/assets/172058970/7bcd7477-8c79-4e1f-8a7d-46aa58bf89f9

Logs

No errors displayed in console

easjfpjpasoepa avatar Jun 07 '24 16:06 easjfpjpasoepa

Godot should free the memory if you free the scene before reloading it. We have no problem swapping out Terrain3D levels in Out of the Ashes. Collision takes a lot of memory. It will be addressed by #278.

TokisanGames avatar Jun 09 '24 03:06 TokisanGames

I have observed this as well. I am freeing the entire scene using SceneTree.change_scene_to_packed(), but memory continues to increase on each load. I wasn't sure if my issue was Terrain3D related, but I did suspect that it was.

OP, can you provide some more details?

liamhendricks avatar Jun 20 '24 13:06 liamhendricks

You both could test debug collision, which uses a static body instead of the physics server.

You could repeatedly enable and disable debug collision in the editor and see if it leaks memory.

You can test a scene with only Terrain3D in it, or try to replicate it in the demo.

We don't use change_scene_to_packed. We have our scene loader as the main scene in the tree, which never changes. Our scene loader loads a scene, attaches it to the SL or removes and frees it.

TokisanGames avatar Jun 20 '24 14:06 TokisanGames

Placing the Terrain3d node as a child of the global node solved the problem for now. Switching scenes may cause the LOD to not function properly, so you need to set up a dummy camera in Terrain3d before switching scenes and then set up an active camera in the scene after switching scenes.

easjfpjpasoepa avatar Jun 22 '24 06:06 easjfpjpasoepa

Your player and camera can also be global. Ours is. There's no need to store your player within levels, or reload them when switching. You can specify any camera at any time with Terrain3D.set_camera().

TokisanGames avatar Jun 22 '24 06:06 TokisanGames

I've continued to not see any issues with memory management, except that full collision takes a large amount of memory, but not an increasing amount.

Collision has been rewritten in #278 and needs testers. It introduces two dynamic modes that consume much less memory. This PR will close this ticket unless there are further issues brought up. Please see if you can continually consume memory in any collision mode using 4.3.

See https://github.com/TokisanGames/Terrain3D/pull/278#issuecomment-2619955778

TokisanGames avatar Jan 28 '25 21:01 TokisanGames