godotengine / godot

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

Game crashes, but unable to recreate in a simple project, potentially a threading issue. #92467

Open baz-atak opened 1 month ago

baz-atak commented 1 month ago

Tested versions

Happens in 4.1.stable, 4.2.stable, 4.3 own debug build.

System information

Godot v4.2.stable - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2080 Ti (NVIDIA; 31.0.15.3623) - AMD Ryzen Threadripper 3960X 24-Core Processor (48 Threads)

Issue description

This may be related to other issues such as #70491 and #72491 which refer to issues when option physics/3d/run_on_seperate_thread is enabled. However I don't think the errors are identical.

I get the following error when running through a version with a traceback enabled.

USER ERROR: FATAL: Index p_index = 4294967295 is out of bounds (count = 184).
   at: LocalVector<struct BVH_Tree<class GodotCollisionObject3D,2,2,128,class GodotBroadPhase3DBVH::UserPairTestFunction<class GodotCollisionObject3D>,class GodotBroadPhase3DBVH::UserCullTestFunction<class GodotCollisionObject3D>,1,struct AABB,struct Vector3>::TNode,unsigned int,1,0>::operator [] (E:\godotBuild\godot-master\core/templates/local_vector.h:177)

================================================================
CrashHandlerException: Program crashed
Engine version: Godot Engine v4.3.beta.custom_build
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[0] LocalVector<BVH_Tree<GodotCollisionObject3D,2,2,128,GodotBroadPhase3DBVH::UserPairTestFunction<GodotCollisionObject3D>,GodotBroadPhase3DBVH::UserCullTestFunction<GodotCollisionObject3D>,1,AABB,Vector3>::TNode,unsigned int,1,0>::operator[] (E:\godotBuild\godot-master\core\templates\local_vector.h:177)
[1] PooledList<BVH_Tree<GodotCollisionObject3D,2,2,128,GodotBroadPhase3DBVH::UserPairTestFunction<GodotCollisionObject3D>,GodotBroadPhase3DBVH::UserCullTestFunction<GodotCollisionObject3D>,1,AABB,Vector3>::TNode,unsigned int,1,0>::operator[] (E:\godotBuild\godot-master\core\templates\pooled_list.h:90)
[2] BVH_Tree<GodotCollisionObject3D,2,2,128,GodotBroadPhase3DBVH::UserPairTestFunction<GodotCollisionObject3D>,GodotBroadPhase3DBVH::UserCullTestFunction<GodotCollisionObject3D>,1,AABB,Vector3>::item_move (E:\godotBuild\godot-master\core\math\bvh_public.inc:123)
[3] BVH_Manager<GodotCollisionObject3D,2,1,128,GodotBroadPhase3DBVH::UserPairTestFunction<GodotCollisionObject3D>,GodotBroadPhase3DBVH::UserCullTestFunction<GodotCollisionObject3D>,AABB,Vector3,1>::move (E:\godotBuild\godot-master\core\math\bvh.h:201)
[4] BVH_Manager<GodotCollisionObject3D,2,1,128,GodotBroadPhase3DBVH::UserPairTestFunction<GodotCollisionObject3D>,GodotBroadPhase3DBVH::UserCullTestFunction<GodotCollisionObject3D>,AABB,Vector3,1>::move (E:\godotBuild\godot-master\core\math\bvh.h:141)
[5] GodotBroadPhase3DBVH::move (E:\godotBuild\godot-master\servers\physics_3d\godot_broad_phase_3d_bvh.cpp:45)
[6] GodotCollisionObject3D::_update_shapes (E:\godotBuild\godot-master\servers\physics_3d\godot_collision_object_3d.cpp:182)
[7] GodotCollisionObject3D::_shape_changed (E:\godotBuild\godot-master\servers\physics_3d\godot_collision_object_3d.cpp:236)
[8] GodotPhysicsServer3D::_update_shapes (E:\godotBuild\godot-master\servers\physics_3d\godot_physics_server_3d.cpp:1736)
[9] GodotPhysicsServer3D::body_test_motion (E:\godotBuild\godot-master\servers\physics_3d\godot_physics_server_3d.cpp:920)
[10] PhysicsServer3DWrapMT::body_test_motion (E:\godotBuild\godot-master\servers\physics_server_3d_wrap_mt.h:261)
[11] PhysicsBody3D::move_and_collide (E:\godotBuild\godot-master\scene\3d\physics\physics_body_3d.cpp:109)
[12] CharacterBody3D::_move_and_slide_grounded (E:\godotBuild\godot-master\scene\3d\physics\character_body_3d.cpp:159)
[13] CharacterBody3D::move_and_slide (E:\godotBuild\godot-master\scene\3d\physics\character_body_3d.cpp:108)
[14] call_with_validated_variant_args_ret_helper<CharacterBody3D,bool> (E:\godotBuild\godot-master\core\variant\binder_common.h:375)
[15] call_with_validated_object_instance_args_ret<CharacterBody3D,bool> (E:\godotBuild\godot-master\core\variant\binder_common.h:663)
[16] MethodBindTR<CharacterBody3D,bool>::validated_call (E:\godotBuild\godot-master\core\object\method_bind.h:538)
[17] GDScriptFunction::call (E:\godotBuild\godot-master\modules\gdscript\gdscript_vm.cpp:2094)
[18] GDScriptInstance::callp (E:\godotBuild\godot-master\modules\gdscript\gdscript.cpp:2050)
[19] Node::_gdvirtual__physics_process_call<0> (E:\godotBuild\godot-master\scene\main\node.h:352)
[20] Node::_notification (E:\godotBuild\godot-master\scene\main\node.cpp:60)
[21] Node::_notificationv (E:\godotBuild\godot-master\scene\main\node.h:50)
[22] Node3D::_notificationv (E:\godotBuild\godot-master\scene\3d\node_3d.h:52)
[23] CollisionObject3D::_notificationv (E:\godotBuild\godot-master\scene\3d\physics\collision_object_3d.h:38)
[24] PhysicsBody3D::_notificationv (E:\godotBuild\godot-master\scene\3d\physics\physics_body_3d.h:41)
[25] CharacterBody3D::_notificationv (E:\godotBuild\godot-master\scene\3d\physics\character_body_3d.h:38)
[26] Object::notification (E:\godotBuild\godot-master\core\object\object.cpp:906)
[27] SceneTree::_process_group (E:\godotBuild\godot-master\scene\main\scene_tree.cpp:957)
[28] SceneTree::_process (E:\godotBuild\godot-master\scene\main\scene_tree.cpp:1042)
[29] SceneTree::physics_process (E:\godotBuild\godot-master\scene\main\scene_tree.cpp:491)
[30] Main::iteration (E:\godotBuild\godot-master\main\main.cpp:4014)
[31] OS_Windows::run (E:\godotBuild\godot-master\platform\windows\os_windows.cpp:1686)
[32] widechar_main (E:\godotBuild\godot-master\platform\windows\godot_windows.cpp:181)
[33] _main (E:\godotBuild\godot-master\platform\windows\godot_windows.cpp:206)
[34] main (E:\godotBuild\godot-master\platform\windows\godot_windows.cpp:220)
[35] WinMain (E:\godotBuild\godot-master\platform\windows\godot_windows.cpp:234)
[36] __scrt_common_main_seh (D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[37] <couldn't map PC to fn name>
-- END OF BACKTRACE --
================================================================

It may be because I change the disabled state of some CharacterBody3D collision shapes to true, but I have been unable to validate this hypothesis, although using set_deferred to set the property does appear to overcome the crashing which might support this theory, although it is difficult to reproduce the crashing. I have been unable to reproduce this issue in another, simpler project.

It may be that I'm doing the wrong thing which is why it's crashing, but to just stop without reporting an error isn't nice. for background: https://forum.godotengine.org/t/crashing-but-why-i-dont-understand-the-error-message/52900/20

Steps to reproduce

I've been unable to create a minimal reproduction project. It might be the complexity is required for the issue to occur, or I've miss-understood was is occurring. It does not happen all the time.

Minimal reproduction project (MRP)

N/A

huwpascoe commented 1 month ago

Are these changes to the colliders are made inside of _physics_process() or some Area3D signal? That's most likely what's crashing.

baz-atak commented 1 month ago

In _physics_process(), but I think it crashes when move_and_slide() is called.

AlexLovelock22 commented 3 weeks ago

Interesting. I'm having the exact same problem right now. Did you fix it?

baz-atak commented 2 weeks ago

@AlexLovelock22 I think the problem is with running the physics in a separate thread, and having a lot of colliders. Turning off running physics in separate thread in the project settings seems to stop the crashing. It might also be the case that you need to defer making changes to the colliders states rather than doing it directly (I had other issues trying that) - but I've not seen it mentioned that you should use set_deferred to do it, so it could be a shortfall in the documentation, something in the documentation that I've missed or a bug in the threading code.