Commit Graph

12 Commits

Author SHA1 Message Date
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
Lukas Tenbrink c9279c1e53 Add classdb_construct_object3 and classdb_register_extension_class6, which are refcount-aware initialization functions (establishing RefCounted objects with a refcount of 1). 2026-04-12 12:29:04 +02:00
Rémi Verschelde e015e8bde4 Remove unused includes in core with clangd-tidy 2026-03-11 06:41:36 +01:00
Thaddeus Crews e380a41752 Style: Add class_db.h includes explicitly 2026-02-26 15:50:28 -06:00
lawnjelly 14a814586a Provide quick access to Object ancestry 2025-06-23 07:11:11 +01:00
Rémi Verschelde d95794ec8a One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".
2023-01-05 13:25:55 +01:00
Marc Gilleron 474cee7daf Rename and expose RefCounted::get_reference_count() 2022-09-21 21:18:54 +01:00
Ignacio Roldán Etcheverry f45f20285c Fix instance binding unreference callback regression
This was a regression from 4469144891

The callback should be called, not only be called when the refcount
reaches 0. For example, the C# callback needs to know when the
refcount reaches 1, in order to swap to a weak GC handle.
2022-08-12 08:43:53 +02:00
Hugo Locurcio 180e5d3028 Remove RES and REF typedefs in favor of spelled out Ref<>
These typedefs don't save much typing compared to the full `Ref<Resource>`
and `Ref<RefCounted>`, yet they sometimes introduce confusion among
new contributors.
2022-05-03 01:43:50 +02:00
Rémi Verschelde fe52458154 Update copyright statements to 2022
Happy new year to the wonderful Godot community!
2022-01-03 21:27:34 +01:00
reduz 4469144891 Redo how instance bindings work
* The harcoded 8 slots are no more and impose limits in the new extension system.
* New system is limitless, although it will impose small performance hit with a mutex.
* Use a token to request the instance binding.

**Warning**: Mono will most likely break as a result of this, will need to be modified to use the new system.
2021-07-08 17:08:12 -03:00
Pedro J. Estébanez 04688b92ff Rename Reference to RefCounted 2021-06-11 18:48:42 +02:00