Am I able to run functions like intersect_ray() from a thread without use of call_deferred()?
I am getting errors that I can only assume are the cause of my thread conflicting with the main thread, and they are inconsistent and happen at random:
ERROR: Condition "space->locked" is true. Returned: false
at: PhysicsDirectSpaceStateSW::intersect_ray (servers\physics\space_sw.cpp:104) - Condition "space->locked" is true. Returned: false
i am fetching the direct space state from a physics_process() loop in my main node like this
var direct_space_state = Global_Variables_3D.world.phys_dir_space
and the loop looks like this:
func _physics_process(delta):
phys_dir_space = get_world().direct_space_state
I am also actively using the same phys_dir_space var in my main thread so I assume this to be the cause of the errors.
the documentation says that I need to access the space state from _physics_process()
to avoid this "locked" error, and yet I am still receiving it.
and here's the call stack from another seemingly physics related error that crashes my project.
ERROR: FATAL: Index p_index = 2 is out of bounds (count = 0).
at: LocalVector<unsigned int,unsigned int,1>::operator [] (C:\Users\Alex\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core/local_vector.h:181) - FATAL: Index p_index = 2 is out of bounds (count = 0).
================================================================
CrashHandlerException: Program crashed
Engine version: Godot Engine v3.5.1.rc.custom_build (46f4047d2a90e49f29d7098d9aa1eb3ba5a79981)
Dumping the backtrace. Please include this when reporting the bug on: https://github.com/godotengine/godot/issues
[0] LocalVector<unsigned int,unsigned int,1>::operator[] (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core\local_vector.h:181)
[1] LocalVector<unsigned int,unsigned int,1>::operator[] (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core\local_vector.h:181)
[2] BVH_Tree<CollisionObjectSW,2,2,128,BroadPhaseBVH::UserPairTestFunction<CollisionObjectSW>,BroadPhaseBVH::UserCullTestFunction<CollisionObjectSW>,1,AABB,Vector3>::_cull_translate_hits (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core\math\bvh_cull.inc:42)
[3] BVH_Tree<CollisionObjectSW,2,2,128,BroadPhaseBVH::UserPairTestFunction<CollisionObjectSW>,BroadPhaseBVH::UserCullTestFunction<CollisionObjectSW>,1,AABB,Vector3>::cull_segment (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core\math\bvh_cull.inc:116)
[4] BVH_Manager<CollisionObjectSW,2,1,128,BroadPhaseBVH::UserPairTestFunction<CollisionObjectSW>,BroadPhaseBVH::UserCullTestFunction<CollisionObjectSW>,AABB,Vector3,1>::cull_segment (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core\math\bvh.h:373)
[5] BroadPhaseBVH::cull_segment (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\servers\physics\broad_phase_bvh.cpp:81)
[6] PhysicsDirectSpaceStateSW::intersect_ray (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\servers\physics\space_sw.cpp:112)
[7] PhysicsDirectSpaceState::_intersect_ray (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\servers\physics_server.cpp:259)
[8] MethodBind6R<PhysicsDirectSpaceState,Dictionary,Vector3 const &,Vector3 const &,Vector<RID> const &,unsigned int,bool,bool>::call (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core\method_bind_ext.gen.inc:415)
[9] Object::call (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core\object.cpp:918)
[10] Variant::call_ptr (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core\variant_call.cpp:1229)
[11] GDScriptFunction::call (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\modules\gdscript\gdscript_function.cpp:1049)
[12] GDScriptInstance::call_multilevel (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\modules\gdscript\gdscript.cpp:1211)
[13] Node::_notification (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\scene\main\node.cpp:58)
[14] Node::_notificationv (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\scene\main\node.h:47)
[15] Spatial::_notificationv (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\scene\3d\spatial.h:52)
[16] Object::notification (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\core\object.cpp:929)
[17] SceneTree::_notify_group_pause (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\scene\main\scene_tree.cpp:1107)
[18] SceneTree::idle (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\scene\main\scene_tree.cpp:608)
[19] Main::iteration (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\main\main.cpp:2298)
[20] OS_Windows::run (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\platform\windows\os_windows.cpp:3543)
[21] widechar_main (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\platform\windows\godot_windows.cpp:176)
[22] _main (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\platform\windows\godot_windows.cpp:198)
[23] main (C:\Users\User_Name\Desktop\Godot_v3.1.1-stable_mono_win64\godot master\godot\platform\windows\godot_windows.cpp:210)
[24] __scrt_common_main_seh (d:\a01\_work\20\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288)
[25] BaseThreadInitThunk
-- END OF BACKTRACE --
================================================================
This fatal error happens right when the thread ends for some reason, even though there are no physics related calls happening then. I wonder if it's somehow related to the first error.