godotengine / godot

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

GridMap reports errors to the Physic server on removing cells #43712

Closed Chaosus closed 3 years ago

Chaosus commented 3 years ago

Godot version: 3.2.3 - 3.2.4

OS/device including version: Win10/GTX1060

Issue description: Removing the cell by calling set_cell_item(x, y, z, -1) will cause errors in the PhysicServer even if there is no physic body attached to cells.

Steps to reproduce: Run attached project. The following code will spam errors to the Output:

image

ERROR: get: Condition "!id_map.has(p_rid.get_data())" is true. Returned: __null
   At: ./core/rid.h:150
ERROR: body_set_state: Condition "!body" is true.
   At: modules/bullet/bullet_physics_server.cpp:675
ERROR: Invalid ID.
   At: modules/bullet/bullet_physics_server.cpp:1551

Minimal reproduction project: GridMapBug.zip

XLIVE99 commented 3 years ago

I encountered this error too. But mine is on gridmap paint and it prints on "Output", so I analyzed this bug. First, these are descriptions of the terms I'm going to use: -Paint: Gridmap paint -Action area: Smallest box that contains a paint (Here's some image for better explanation): Action_area

The bug only occurs if action happened in a frame which action area bigger than octant size. So in order to reproduce the bug, you need to: -Undo + Paint -Undo + Redo + Erase (Mouse right click) -Clear selection + Paint -Cut selection + Paint If these actions is not bigger than octant size then the bug wont appear. However the bug can still appear while the action area is smaller than or equal to octant size in some special conditions:

Gridmap octant size setted to 2 for easier visualization. All action areas which contains both green and red tile will cause the bug.

Bugmap_octant2

If octant size setted to 3 then all areas as shown above will increase 1 cell, like this: resim_2021-03-22_165305

Sometimes the bug will appear as infinite loop (only output if input happens such as mouse motion), and sometimes it happens once or third. It depends on where you click first. If infinite loop happens then in order to get rid of the bug, you need to paint and erase the corresponding tile.

Undo + Redo + Erase doesn't produce bug always, as mentioned above only erasing tiles which cause infinite loop will give error once.

Hope this helps to solve the bug.