Commit Graph

9498 Commits

Author SHA1 Message Date
HP van Braam 7ab8328204 Don't flush the message queue before a MainLoop is iterating
Allowing this breaks several assumptions in the engine, normally this
doesn't occur but when using the WTP it can occur. For instance during
resource loading the message queue is serviced during tear down.

This means this situation can be created from user code if they do async
resource loading in the `_load` of a resource in the main scene.

This also makes the MainLoop report that it IS iterating during tests as
the tests expect the message queue to be serviced even though no main
loop is running.
2026-06-09 15:29:53 +02:00
HP van Braam b88a62f805 Fix ResourceLoader deadlocks
This fixes several issues:
 * There was a bug in the cycle detection. It was possible for the cycle
   detection to fail because the current thread isn't in the list. Fix
   this by just seeing if any of the next threads were already in the
   cycle.
 * By way of an optimization the thread_waiting_on bookkeeping was done
   under the same thread_load_mutex as the cycle detection. But there is
   also an early exit after yields. If we exit through the yield the
   thread_waiting_on entry is stale and can cause other threads to fail
   to do cycle detection.
 * When multiple threads end up finishing a resource simultaneously
   anyway, probably through cycle detection, there's a small chance that
   the original thread finished more-or-less at the same time if the
   original thing blocking load completed. We solve this now by letting
   only one of the threads do the initial registration.
2026-06-08 04:57:26 +02:00
Thaddeus Crews 93d16cc84c Merge pull request #119757 from hpvb/fix-threaded-loader-again
Fix `ResourceLoader::load_threaded_get()` deadlocks
2026-05-29 10:47:41 -05:00
Thaddeus Crews bc209b4f1d Merge pull request #119598 from nikitalita/ensure-bptc-textures
Ensure that BPTC LayeredTexture images get compressed with same signedness
2026-05-29 10:47:39 -05:00
HP van Braam 374102cfbe Fix ResourceLoader::load_threaded_get() deadlocks
This fixes several issues in ResourceLoader
 * When waiting on resources being loaded on the main thread it is
   possible that the resource was waiting on the message queue. Flush
   the message queue in this situation. This was an existing bug.
 * When re-starting a load for deadlock-prevention reasons, and this
   type of resource has nested resources and uses resource changed
   connections we end up with references to resourcese being deleted
   as duplicates in the dependent task. We now keep a reference to these
   resources for the duration of the dependent load task. This closes
   the race but does not entirely eliminate it during intial import.
   This is an existing bug seemingly specific to TileSetSource but there
   might be others.
 * When threads are waiting during teardown we ended up deadlocking
   because the waiting thread would never end up completing. This is a
   bug introduced by f63ab5f
 * When a thread loading a resource ends up calling back into the
   WorkerThreadPool to wait cooperatively it expects that other threads
   complete, or new requests are made, so that work moves forward. If
   all OTHER threads end up blocked by the WorkerThreadPool waiting
   thread then no forward progress can be made anymore. We now solve
   this problem by yielding whenever we are blocked by another task. We
   wake up each every task whenever any progress is made to see if
   further progress can be made. This is a bug introduced by f63ab5f
 * When dependencies get introduced while loading it is possible to form
   a dependency cycle. Normally this isn't a problem but when all
   threads are already waiting when the cycle is introduced no forward
   progress can be made anymore. We now break such cycles. This is a bug
   introduced by f63ab5f
2026-05-29 16:12:02 +02:00
Thaddeus Crews 6137953493 Merge pull request #119651 from Ivorforce/clarify-hash-compare
Clarify `hash_compare` semantics on `Variant`.
2026-05-22 10:57:56 -05:00
Lukas Tenbrink 103b82048f Clarify hash_compare semantics on Variant. 2026-05-22 12:00:02 +02:00
nikitalita 3a49491ff0 Ensure that BPTC LayeredTexture images get compressed with same signedness 2026-05-19 23:04:00 -07:00
Pāvels Nadtočajevs 735827bd78 [Import] Fix empty columns importing as invalid English translation. 2026-05-19 14:48:41 +03:00
Thaddeus Crews 2c5bdd1f9c Merge pull request #119510 from van800/shakhov/fixes
open_dynamic_library(String(), library, &data) should only be called for apple
2026-05-18 11:06:26 -05:00
Thaddeus Crews 8ae90e9442 Merge pull request #119495 from m4gr3d/fix_main_path_use_for_android
[Android] Fix the use of `--main-pack` in template builds
2026-05-18 11:06:25 -05:00
Ivan Šachov e744959de5 avoiding an incorrect ERR_FILE_NOT_FOUND report when the DLL exists but fails to load for another reason
Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com>
2026-05-16 21:55:33 +02:00
Fredia Huya-Kouadio 948032c89c [Android] Fix the use of --main-pack 2026-05-15 23:03:54 -07:00
Jan Haller dd29447f44 Warn when registering RefCounted as engine singleton
The `Engine::Singleton` struct stores a raw `Object *`, so registering
a `RefCounted` only works if some external `Ref<>` keeps it alive. This
pattern is fragile and can lead to UB, especially with GDExtension.
2026-05-15 11:00:16 +02:00
Thaddeus Crews afdab2d6b3 Merge pull request #119394 from ManpreetXSingh/fix/double-ref
Fix Resources loaded using `ResourceLoader.load_threaded_get` are never unloaded
2026-05-11 10:59:50 -05:00
Manpreet Singh 9caa8180e9 fix: double ref 2026-05-11 08:08:21 +05:30
Lukas Tenbrink 7852cb7887 Update GDCLASS / GDSOFTCLASS comments. 2026-05-08 23:47:35 +02:00
Thaddeus Crews 599f2bd5b9 Merge pull request #118824 from hpvb/fix-118085
Fix a race in `ResourceLoader::load_threaded_request()`
2026-05-06 14:56:33 -05:00
Thaddeus Crews 3033644920 Merge pull request #119254 from Ivorforce/casts-are-so-4.6
Deprecate GDExtension's `object_cast_to` and `classdb_get_class_tag`, in favour of `is_class` casts.
2026-05-06 10:53:32 -05:00
Lukas Tenbrink 7c8df516ba Deprecate object_cast_to and classdb_get_class_tag, in favour of is_class. 2026-05-05 21:44:22 +02:00
HP van Braam f63ab5fbd9 Fix a race in ResourceLoader::load_threaded_request()
When multiple threads try to load the same sub-resource the
ResourceLoader's anti-deadlock protection thinks that the other threads
loading the dependency are old threads blocked on a dependency.

The current thread will then immediately start to load the sub-resource
since they can't wait for it. This can then lead to multiple threads
loading the same resource concurrently.

We fix the problem by recording in the task when loading has ACTUALLY
started, and if so we simply wait.

This is no worse than before, at the point where we are waiting now we
previously re-started the load entirely.

Tested by running the MRP from the below issue (with and without asan
and msan), and loading and running various public and private Godot
projects.

This also fixes a use-after-free on resource_changed_connections when
multiple threads end up running the same import. This is a pre-existing
bug but this code widened the race window.

This also fixes a pre-existing memory leak in load_threaded_request,
when the user calls the function we capture the Ref<LoadToken> but
immediately drop the ref. Causing the refcount to go to 1. Later in
_run_load_task we unreference manually, bringing the refcount to 0. This
then later prevents the Ref<> from memdeleting the LoadToken.

This fixes #118085
2026-05-05 15:11:05 +02:00
Dimitri Sukhankin e07737e0ba Add better error message when trying to decompress ZSTD with decompress_dynamic 2026-05-04 22:01:06 +04:00
Thaddeus Crews 176b795177 Merge pull request #119174 from StarryWorm/remove-classdb-pragmas
Fix pragma includes
2026-05-04 12:40:40 -05:00
Enzo Novoselic 1b98247ef8 Fix RequiredResult<T> not being parsed properly by include-cleaner 2026-05-02 14:02:01 -04:00
Thaddeus Crews 0b41f26b9b Merge pull request #119090 from ttencate/fix/issue_119085_shift_enter
Add Shift+Enter and Shift+KpEnter as default shortcuts for newline
2026-04-30 10:58:05 -05:00
Mikael Hermansson 6103c0bc42 Add error to error messages in FileAccessPack 2026-04-29 18:43:04 +02:00
Thomas ten Cate 50114457c5 Add Shift+Enter and Shift+KpEnter as default shortcuts for newline
These conflict with `ui_text_completion_replace` (accept autocompletion), but
the latter seems to take precedence if an autocomplete popup is open, so this
still works as expected.

Fixes #119085
2026-04-29 17:36:05 +02:00
HolonProduction 612475a680 GDScript: Track columns by raw string offsets 2026-04-26 21:32:46 +02:00
Thaddeus Crews 01603e77df Merge pull request #118678 from hpvb/fix-115173
Fix race in `RefCounted::unreference()`
2026-04-22 09:58:32 -05:00
Thaddeus Crews 0e25644655 Merge pull request #118796 from deralmas/gotta-go-wrap
Buildsystem: Simplify `format_buffer` utility method
2026-04-22 09:58:29 -05:00
Thaddeus Crews ba11d28426 Merge pull request #118055 from realbucketofchicken/ipv6-shortening
Fix regression when parsing a shortened IPv6 Address
2026-04-21 16:46:03 -05:00
Dery Almas e4dcf1d852 Buildsystem: Simplify format_buffer utility method
This method is used to generate headers for embedding files into the binary
(think about the new `#embed` feature in C23 and C++26).

While the stringification step itself was plenty fast, it then proceeded
to wrap everything using the `textwrap` module. `textwrap` is *very*
slow, as it's apparently optimized for human text.

This patch reimplements the wrapping logic using a simple regex,
resulting in a tremendous speed improvement (~6x), and switches to `map`
for the stringification itself (thanks Rémi!)

It also removes a (practically) unused argument, `initial_indent`.

The generated files are pretty much the same, with a tiny difference in
line length (for some reason the old logic overshot the requested line
length)
2026-04-21 23:18:42 +02:00
bucket 9e674ece11 fix shortened ipv6 parsing 2026-04-21 15:18:46 +02:00
Mister Ky 9eb3a04edf Finish mapping missing deprecated types for GDExtension 2026-04-21 00:45:59 +03:00
Thaddeus Crews b2b661d3bc Merge pull request #118750 from dsnopek/gdext-cleanup-register-extension-class6
GDExtension: Clean up types for new `classdb_register_extension_class6`
2026-04-20 14:31:56 -05:00
Thaddeus Crews 92846d7c3e Merge pull request #112035 from Ivorforce/no-unsafe-new-overloads
Change `new` overloads to use a tag instead of a pointer
2026-04-20 09:15:47 -05:00
Thaddeus Crews dd6a398e90 Merge pull request #118355 from allenwp/hdr-output-basic-project-setting
Change `display/window/hdr/request_hdr_output` project setting to be a basic setting.
2026-04-20 09:15:39 -05:00
Thaddeus Crews e91640c755 Merge pull request #118773 from dsnopek/gdextension-placeholder-no-deprecated
GDExtension: Use `create_instance3` for placeholder classes
2026-04-20 09:15:38 -05:00
Lukas Tenbrink 9e43daa74d Change new overloads to use a tag instead of a pointer, which can lead to problems. Inline the new definition to save on a call. 2026-04-20 15:46:34 +02:00
David Snopek 10685b471e GDExtension: Use create_instance3 for placeholder classes
Co-authored-by: Mike Owens <mike@mikeowens.us>
2026-04-20 06:41:44 -05:00
David Snopek 470408515e GDExtension: Don't memdelete(gdtype) on placeholders 2026-04-19 12:25:51 -05:00
David Snopek 7375ee7736 GDExtension: Clean up types for new classdb_register_extension_class6 2026-04-19 08:19:14 -05:00
Thaddeus Crews f1edeb4acc Merge pull request #118527 from KoBeWi/ignore_error_problem_fixed
Don't print UID errors when cache is not initialized
2026-04-18 07:28:36 -05:00
HP van Braam 6409ce6bb6 Fix race in RefCounted::unreference()
When two threads unreference() a RefCounted Object at the same time there's
a potential race.

Thread A sees rc_val == 1, enters the if() block.
Thread B sees rc_val == 0, enters the if() block.

Thread A gets scheduled out, or is simply scheduled on a slower core and
Thread B finishes, returning die = true. Thread B then frees the Object.

Some time during or after ~Object() Thread A wakes up and tries to call
methods on the Object, which is either destroyed or in the process of being
destroyed, leading to a use-after-free.

We fix the problem by counting how many threads are currently inside
the critical section, and blocking returning die = true as long as there are
still other threads potentially alive.

Tested by running with --test and by opening and playing various public and
private Godot projects.

This fixes #115173
2026-04-17 12:24:56 +02:00
Thaddeus Crews 9b4b3831d2 Merge pull request #118588 from Bromeon/feature/more-required-ptrs
Use `RequiredParam`/`RequiredResult` in several more APIs
2026-04-16 09:41:13 -05:00
Thaddeus Crews 790c68368f Merge pull request #118590 from Bromeon/feature/required-ptr-conversion
Add `RequiredParam` -> `RequiredResult` conversion
2026-04-16 09:41:12 -05:00
Kaleb Reid f973e3e346 Remove p_ and add r_ prefixes to argument names 2026-04-15 13:47:15 -07:00
Thaddeus Crews 3f63a400fa Merge pull request #118503 from m4gr3d/update_perfetto_tracing
Hook up `perfetto` script and frame profiling logic
2026-04-15 14:02:37 -05:00
Thaddeus Crews 37e53d7a54 Merge pull request #118609 from HolonProduction/rm-cmt
Remove obsolete header guard comment
2026-04-15 14:02:34 -05:00
Thaddeus Crews 66dd6fe737 Merge pull request #118582 from Ivorforce/is_class_sn
Change `Object::is_class` to take `StringName` instead of `String`, for better performance
2026-04-15 14:02:32 -05:00