Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in BVH when using move_and_slide or move_and_collide with multi-threaded physics server #53496

Closed
pouleyKetchoupp opened this issue Oct 6, 2021 · 1 comment

Comments

@pouleyKetchoupp
Copy link
Contributor

pouleyKetchoupp commented Oct 6, 2021

Godot version

3.4-beta6

System information

Windows 10

Issue description

Based on #24050 (comment).

Random crash happens in the BVH with multi-threaded physics server due to possible calls to _update_shapes on both the main thread (test_body_motion in _physics_process) and the physics server thread syncing commands.

The repro case is 2D only on 3.x, but it probably also happens on master and in 3D.
Edit: it looks like the issue is on 3.x only and was fixed on master with #45852.

Callstack on the main thread:

 	godot.windows.tools.64.exe!LocalVector<BVH_Tree<CollisionObject2DSW,2,128,1,Rect2,Vector2>::TNode,unsigned int,1>::operator[](unsigned int p_index) Line 162	C++
 	godot.windows.tools.64.exe!PooledList<BVH_Tree<CollisionObject2DSW,2,128,1,Rect2,Vector2>::TNode,1>::operator[](unsigned int p_index) Line 70	C++
 	godot.windows.tools.64.exe!BVH_Tree<CollisionObject2DSW,2,128,1,Rect2,Vector2>::item_move(BVHHandle p_handle, const Rect2 & p_aabb) Line 119	C++
 	godot.windows.tools.64.exe!BVH_Manager<CollisionObject2DSW,1,128,Rect2,Vector2,1>::move(BVHHandle p_handle, const Rect2 & p_aabb) Line 196	C++
 	godot.windows.tools.64.exe!BVH_Manager<CollisionObject2DSW,1,128,Rect2,Vector2,1>::move(unsigned int p_handle, const Rect2 & p_aabb) Line 143	C++
 	godot.windows.tools.64.exe!BroadPhase2DBVH::move(unsigned int p_id, const Rect2 & p_aabb) Line 42	C++
 	godot.windows.tools.64.exe!CollisionObject2DSW::_update_shapes() Line 187	C++
 	godot.windows.tools.64.exe!CollisionObject2DSW::_shape_changed() Line 240	C++
 	godot.windows.tools.64.exe!Physics2DServerSW::_update_shapes() Line 1295	C++
 	godot.windows.tools.64.exe!Physics2DServerSW::body_test_motion(RID p_body, const Transform2D & p_from, const Vector2 & p_motion, bool p_infinite_inertia, float p_margin, Physics2DServer::MotionResult * r_result, bool p_exclude_raycast_shapes, const Set<RID,Comparator<RID>,DefaultAllocator> & p_exclude) Line 944	C++
 	godot.windows.tools.64.exe!Physics2DServerWrapMT::body_test_motion(RID p_body, const Transform2D & p_from, const Vector2 & p_motion, bool p_infinite_inertia, float p_margin, Physics2DServer::MotionResult * r_result, bool p_exclude_raycast_shapes, const Set<RID,Comparator<RID>,DefaultAllocator> & p_exclude) Line 257	C++
 	godot.windows.tools.64.exe!KinematicBody2D::move_and_collide(const Vector2 & p_motion, bool p_infinite_inertia, KinematicBody2D::Collision & r_collision, bool p_exclude_raycast_shapes, bool p_test_only, bool p_cancel_sliding, const Set<RID,Comparator<RID>,DefaultAllocator> & p_exclude) Line 1042	C++

Callstack on the physics thread:

 	godot.windows.tools.64.exe!VectorWriteProxy<CollisionObject2DSW::Shape>::operator[](int p_index) Line 51	C++
 	godot.windows.tools.64.exe!CollisionObject2DSW::_update_shapes() Line 169	C++
 	godot.windows.tools.64.exe!CollisionObject2DSW::_set_transform(const Transform2D & p_transform, bool p_update_shapes) Line 93	C++
 	godot.windows.tools.64.exe!Body2DSW::set_state(Physics2DServer::BodyState p_state, const Variant & p_variant) Line 271	C++
 	godot.windows.tools.64.exe!Physics2DServerSW::body_set_state(RID p_body, Physics2DServer::BodyState p_state, const Variant & p_variant) Line 751	C++
 	godot.windows.tools.64.exe!CommandQueueMT::Command3<Physics2DServer,void (__cdecl Physics2DServer::*)(RID,enum Physics2DServer::BodyState,Variant const &),RID,enum Physics2DServer::BodyState,Variant>::call() Line 300	C++
 	godot.windows.tools.64.exe!CommandQueueMT::flush_one(bool p_lock) Line 442	C++
 	godot.windows.tools.64.exe!CommandQueueMT::wait_and_flush_one() Line 479	C++
 	godot.windows.tools.64.exe!Physics2DServerWrapMT::thread_loop() Line 60	C++

Steps to reproduce

Using the MRP, just try starting the game until it crashes immediately (happens about once every 4 times for me).

Minimal reproduction project

Sonic Outbreak project from #24050:
Sonic_Outbreak.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants