godotengine / godotengine/godot
`call_deferred()` does not get called on the main thread when coming from `load_threaded_request()`
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Reproducible in:
- v4.4.stable.official [4c311cbee]
- v4.5.stable.official [876b29033]
- v4.6.1.rc1.official [7bfffc846]
- current master (v4.7.dev) [20d58a38c]
### System information
Godot v4.7.dev (20d58a38c) - Nobara Linux 43 (KDE Plasma Desktop Edition) on Wayland - X11 display driver, Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3070 (nvidia; 590.48.01) - AMD Ryzen 9 5900X 12-Core Processor (24 threads) - 31.25 GiB memory
### Issue description
When using `call_deferred()` it is expected that the function will be called after all processing is done on *the main thread*. The documentation and demo projects state as much and use it as such.
However, when using `load_threaded_request()` to load a resource that then uses `call_deferred()` in either the `_init()` function or a getter/setter for an exported property etc. the resulting call will still be on a thread.
This has led to inconsistent freezes during playtests of my game, varying both depending on OS and hardware.
Here is a backtrace from one of the people that it occurred for (using a version of the editor with debug symbols):
### Steps to reproduce
Create any script that extends `Resource` and calls a function with `call_deferred()`, then load this resource with `load_threaded_get()`. You can observe the function being called in a thread by placing a break point.
Alternatively:
1. Download the MRP
2. Run the loader scene
3. It should break at the function in `init_resource.gd` with a thread number rather than "Main Thread" as the thread.
### Minimal reproduction project (MRP)
[call_deferred_on_thread.zip](https://github.com/user-attachments/files/25289114/call_deferred_on_thread.zip)
Contributor guide
Assessment
This issue has not been assessed yet.