godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.48k stars 21.08k forks source link

Gridmap static memory leak #57746

Closed me2beats closed 2 years ago

me2beats commented 2 years ago

Godot version

3.4.2

System information

Windows, Linux

Issue description

static memory grows unexpectedly when setting gridmap cell to -1 (which means removing the cell)

Steps to reproduce

  1. create any meshlib (I made it from a scene with a single CubeMesh, without any material/collision etc)
  2. create a scene with gridmap with this script:
    
    extends GridMap

func _physics_process(delta): set_cell_item(0,0,0,0) set_cell_item(0,0,0,-1)


3. run the scene

As you can see in debugger, static memory slowly grows.
Also it's not cleared when using clear()/queue_free()

### Minimal reproduction project

_No response_
me2beats commented 2 years ago

Godot 4 also has this problem

KYRYAMBA commented 2 years ago

8x8_Oct8 16x16_Oct8 16x16_Oct16 64x64_Oct8 64x64_Oct64 32x32_Oct8_Bullet

Check project run on Godot Physics 3.3.3 - 3.4.2. GridMapIssue.zip

Acknowledged. Tested it on versions 3.3.3 - 3.4.2. Windows x64. Here's what memory leak looks like during sample events in game with world generation. Doesn't help clear() -> queue_free() of GridMap, and scene change either. The memory stays clogged. Checked my project on different conditions, least leaks in 8x8 chunk and Octant 8. But throughout they appear. unfortunately the size of such a small chunk is not much of any game will fit. Less leaks on BULLET, but the speed of 12-20ms in 32x32 in 1 frame will not allow to use it. The higher the chunk size, the more memory leakage. The nature of leaks at chunks higher than 8x8 is always the same - the next chunk and memory addition size between chunks is always about 2-2.5 times larger than the previous one.

Very unpleasant bug!

lawnjelly commented 2 years ago

Already fixed in 3.x by #57561. (Notice the similarity with #57555)

Not absolutely sure if the fix was in by 3.4.3 RC 1 but should be in next 3.4.3, and next 3.5 beta.

There's some slight juggling of static memory still now but the major leak from BVH is gone. The fix is pending in 4.0 as part of #57630.

KYRYAMBA commented 2 years ago

Already fixed in 3.x by #57561. (Notice the similarity with #57555)

Not absolutely sure if the fix was in by 3.4.3 RC 1 but should be in next 3.4.3, and next 3.5 beta.

There's some slight juggling of static memory still now but the major leak from BVH is gone. The fix is pending in 4.0 as part of #57630.

Checked on 3.4.3 RC1 - still same

lawnjelly commented 2 years ago

Yeah I just checked, the fix must have just missed that release, it was only merged day before I think or so. Will be in the next one. :+1:

You can try the artifact build (green arrow) from the PR if you want to test.