Open paul-deva opened 1 year ago
Issue persists in 4.0. beta 6
Seems reproducible in latest master
(9ab388c146895cfacf87d09d28c148e186f348b6).
Here's a gdb backtrace of where it seems to be stuck, when running the first example:
(gdb) bt
#0 0x00007f8ec289d776 in __futex_abstimed_wait_common () from /lib64/libc.so.6
#1 0x00007f8ec289fde8 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libc.so.6
#2 0x000000000a5ed093 in Semaphore::wait (this=0x7f8eac7fdcd0) at ./core/os/semaphore.h:65
#3 WorkerThreadPool::wait_for_task_completion (this=0xd673580, p_task_id=58) at ./core/object/worker_thread_pool.cpp:357
#4 0x000000000a61f14e in call_with_variant_args_ret_helper<__UnexistingClass, Error, long, 0ul> (p_instance=0xd673580,
p_method=(Error (__UnexistingClass::*)(__UnexistingClass * const, long)) 0xa5ecd2c <WorkerThreadPool::wait_for_task_completion(long)>, p_args=0x7ffcc5ba0df8, r_ret=..., r_error=...) at ./core/variant/binder_common.h:755
#5 0x000000000a61c9d7 in call_with_variant_args_ret_dv<__UnexistingClass, Error, long> (p_instance=0xd673580,
p_method=(Error (__UnexistingClass::*)(__UnexistingClass * const, long)) 0xa5ecd2c <WorkerThreadPool::wait_for_task_completion(long)>, p_args=0x7ffcc5ba0f28, p_argcount=1, r_ret=..., r_error=..., default_values=...)
at ./core/variant/binder_common.h:534
#6 0x000000000a61a086 in MethodBindTR<Error, long>::call (this=0xd601250, p_object=0xd673580, p_args=0x7ffcc5ba0f28, p_arg_count=1, r_error=...) at ./core/object/method_bind.h:492
#7 0x00000000062706f8 in GDScriptFunction::call (this=0xf6bc7d0, p_instance=0xf6b9070, p_args=0x0, p_argcount=0, r_err=..., p_state=0x0) at ./modules/gdscript/gdscript_vm.cpp:1781
#8 0x00000000061b3975 in GDScriptInstance::callp (this=0xf6b9070, p_method=..., p_args=0x0, p_argcount=0, r_error=...) at ./modules/gdscript/gdscript.cpp:1892
#9 0x00000000083fc9f0 in Node::_gdvirtual__ready_call<false> (this=0xf6bb790) at ./scene/main/node.h:322
#10 0x000000000834d606 in Node::_notification (this=0xf6bb790, p_notification=13) at ./scene/main/node.cpp:186
#11 0x0000000005ccad68 in Node::_notificationv (this=0xf6bb790, p_notification=13, p_reversed=false) at ./scene/main/node.h:49
#12 0x0000000005ccb669 in CanvasItem::_notificationv (this=0xf6bb790, p_notification=13, p_reversed=false) at ./scene/main/canvas_item.h:45
#13 0x0000000008be6757 in Node2D::_notificationv (this=0xf6bb790, p_notification=13, p_reversed=false) at ./scene/2d/node_2d.h:37
#14 0x000000000a5cd4e3 in Object::notification (this=0xf6bb790, p_notification=13, p_reversed=false) at ./core/object/object.cpp:796
#15 0x000000000834da5b in Node::_propagate_ready (this=0xf6bb790) at ./scene/main/node.cpp:230
#16 0x000000000834d9db in Node::_propagate_ready (this=0xf62a770) at ./scene/main/node.cpp:221
#17 0x000000000835e694 in Node::_set_tree (this=0xf62a770, p_tree=0xf62a280) at ./scene/main/node.cpp:2897
#18 0x0000000008370aea in SceneTree::initialize (this=0xf62a280) at ./scene/main/scene_tree.cpp:448
#19 0x000000000567fdeb in OS_LinuxBSD::run (this=0x7ffcc5ba6880) at platform/linuxbsd/os_linuxbsd.cpp:900
#20 0x00000000056770c0 in main (argc=10, argv=0x7ffcc5ba6e68) at platform/linuxbsd/godot_linuxbsd.cpp:74
CC @RandomShaper
The call to create_trimesh_shape()
calls in turn ArrayMesh::surface_get_arrays()
, which in turn calls RenderingServer::get_singleton()->mesh_surface_get_arrays()
. The latter function, since it has to return data, requires the RenderingServer
to be up to date with pending calls in the queue. That is only possible if you let the main loop run. You can achieve that by putting the task in flight and poll for completion, like this (do_stuff()
omitted);
var task
func _ready():
task = WorkerThreadPool.add_task(Callable(self, \"do_stuff\"))
func _process(_delta):
if task && WorkerThreadPool.is_task_completed(task):
task = null
We may need to improve in the area of informing the user about the issue, but I would say this is expected behavior.
Godot version
4.0. beta 6 official [7f8ecffa5]
System information
Windows 10, Vulkan API 1.2.0, NVIDIA GeForce RTX 3070
Issue description
Edit: Originally posted as an issue for version 4.0. beta 5 official [89a33d28f]. Issue exists for beta 6 as described.
Calling the
<ArrayMesh>.create_trimesh_shape()
function in a worker pool task causes the game to hang for what seems to be indefinitely. The same behavior happens with a single task and with group tasks.One way I've found to make the problematic code work is to call the trimesh function as deferred:
This fixes both of the example scripts.
I'm submitting this as a bug because doing the whole process of generating a mesh by specifying vertices, indices, materials and even generating normals and calling
st.index()
all work fine on the WorkerThreadPool task and the trimesh function is the only issue I've stumbled upon.Steps to reproduce
Create a new project with a
Node3D
node and attach one of the two following scripts to it:Example script with one task:
Example script with a group task:
Run the game and it will hang/freeze/become unresponsive
Minimal reproduction project
N/A