Handle object destruction during Godot->Rust call - #1671
Open
Bromeon wants to merge 3 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 |
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
Bromeon
force-pushed
the
bugfix/dead-object-in-calls
branch
from
August 3, 2026 22:02
286c85d to
baa608c
Compare
Contributor
|
This prevents the full engine crash, but I still get this error message: ERROR: Destroyed the Godot object during a Godot -> Rust call on it.
The engine may access the object after the call returns, which is undefined behavior. Do not drop the last
reference to an object inside a call on that same object; defer it past the call instead.
object: Base { id: -9223372001454848550, class: InkVariableWatcher, refc: 0 }
at: godot_core::storage::instance_storage::report_destruction_during_call (/home/greenfox/.cargo/git/checkouts/gdext-067f4b88e7bd088f/baa608c/godot-core/src/storage/instance_storage.rs:378)
GDScript backtrace (most recent call first):
[0] continue_story (res://addons/gdrs_ink/long_story_example.tscn::GDScript_l4es0:39)
[1] choice_made (res://addons/gdrs_ink/long_story_example.tscn::GDScript_l4es0:70) |
Member
Author
|
Yes, this is an upstream issue which I'm currently investigating. The error message makes it loud rather than obscure, but ideally we can address this in Godot itself. |
User code can drop the last reference to the receiver mid-call, e.g. a signal handler nulling the emitter, or free() it. The storage was then destroyed under an active bind guard, which crashed the process. The storage now counts claims: Godot holds one from construction to destruction, each ongoing call holds one. Removing the last claim deallocates. The Godot object itself still dies; only the Rust part is kept alive.
The Rust side survives such a destruction, but the engine may still dereference `this` after the callback returns, which is UB. Print an error naming the class and the way out, once per class since the pattern usually repeats.
Bromeon
force-pushed
the
bugfix/dead-object-in-calls
branch
from
August 10, 2026 23:24
b29e95d to
ccce181
Compare
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.