Enabling collision increases memory consumption each time the scene is reloaded.
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
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.
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?
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.
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.
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().
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