Defer storage destruction during Godot->Rust call - #1671
Open
Bromeon wants to merge 4 commits into
Open
Conversation
Bromeon
enabled auto-merge
August 2, 2026 13:28
|
API docs are being generated and will be shortly available at: https://godot-rust.github.io/docs/gdext/pr-1671 |
For `RefCounted` objects, user code can drop the last ref to itself mid-call (e.g. a signal handler nulling the emitter), which previously freed the storage under the active instance. Now the storage counts "claims" on itself (Godot's + 1 per call on the stack), and is freed by whoever releases the last one.
The weighed alternatives and cost tables belong in the design notes, not in rustdoc. Keep the conclusion and the one non-obvious constraint.
The claim keeps the storage alive, but the Godot object itself cannot be kept: neither free() nor the last reference drop is vetoable. Godot then dereferences a dangling `this` after the callback returns, e.g. in Object::_notification_forward(). Reuse the claim counter to detect the situation and report it, instead of letting it stay silent. Manually managed classes are excluded, since free() during a call on the object is an established pattern.
Bromeon
force-pushed
the
bugfix/dead-object-in-calls
branch
from
August 2, 2026 15:29
a3350a9 to
286c85d
Compare
Bromeon
disabled auto-merge
August 2, 2026 15:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For
RefCountedobjects, user code can drop the last ref to itself mid-call (e.g. a signal handler nulling the emitter), which previously freed the storage under the active instance.I did not go the route of GDScript to add a strong-ref to every Godot->Rust call, for multiple reasons:
NOTIFICATION_PREDELETE)Instead, the storage now counts "claims" on itself (Godot's + 1 per call on the stack), and is freed by whoever releases the last one. This is a bit more complex but retains the benefits of the old version.
Fixes #1666, now covered via itest
signal_emitter_destroyed_during_own_call.