godotengine / godot

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

Infinite loop in Physics2DServerSW::_update_shapes with Multi-Threaded physics #35017

Open DrMoriarty opened 4 years ago

DrMoriarty commented 4 years ago

Bugsquad note: This issue has been confirmed several times already. No need to confirm it further.


Godot version: Godot 3.2.beta 6 (commit 02cd144222)

OS/device including version: MacOSX 10.14.6 (18G95)

Issue description:

I have a lot of KinematicBody2D in one scene. In _physics_process I call move_and_collide and some times the game hungs up with logs:

ERROR: remove: Condition ' p_elem->_root != this ' is true.
   At: ./core/self_list.h:84.

This lines repeates many times. Actually infinite amount of times, because it prints from the infinite loop.

I catched the bug with xcode debugger and it shows me that the problem is in void Physics2DServerSW::_update_shapes(): https://github.com/godotengine/godot/blob/02cd1442227127604549159d66b9bfc68a193dd3/servers/physics_2d/physics_2d_server_sw.cpp#L1421

I have no ideas why pending_shape_update_list became broken. Does anybody have?

Steps to reproduce:

Minimal reproduction project:

DrMoriarty commented 4 years ago

Also I double checked that all my object manipulations was in physics frame. Also set all timer and tweens to physics process mode.

DrMoriarty commented 4 years ago

The bug only reproduced in multi-threaded physics. When I set physics/2d/thread_model to Single-Safe all works as expected.

Xrayez commented 4 years ago

I recently tested similar multi-threaded physics issue in https://github.com/godotengine/godot/issues/29369#issuecomment-572592562.

creikey commented 4 years ago

Perhaps a read-write lock could be used to mitigate this issue on the pending shape update list? As I cannot reliably reproduce I can't test.

KoBeWi commented 3 years ago

Can anyone still reproduce this bug in Godot 3.2.3 or any later release?

If yes, please ensure that an up-to-date Minimal Reproduction Project (MRP) is included in this report (a MRP is a zipped Godot project with the minimal elements necessary to reliably trigger the bug). You can upload ZIP files in an issue comment with a drag and drop.

yuraj11 commented 3 years ago

I am still getting similar issue (v3.2.4.rc.mono.custom_build.4b9b9ed2f), multi-thread rendering is on: ERROR: SelfList<class CollisionObject2DSW>::List::remove: Condition "p_elem->_root != this" is true. (core/self_list.h:84) happens randomly when trying to call .instance() on scene which contains physics body (in my case KinematicBody2D) in thread (C#).

EDIT: Well it doesn't happen with physics Multi-Threaded option for me.

Reapetitive commented 3 years ago

I still get this problem in 3.3.3, even with single-safe. With multi-threaded it happens way more often. I use many kinematic bodies.

hodgerti commented 2 years ago

I am having this issue on 3.3.4-stable, but resolved it by switching from Multi-Threaded Physics thread model to Single-Safe.

Here is a visual studio minidump: _update_shapes-bug-godot.windows.tools.64.dmp.zip

rburing commented 1 year ago

Somebody please attach a reproduction project. From the information so far it seems to be a 3.x issue, so I'm changing the milestone. If it is reproducible in 4.0 then please let us know (with a reproduction project).