Skip to content

Commit d1cb1e1

Browse files
committed
Fix regression in mechanism to hold objects while emitting
1 parent 8ebf8ae commit d1cb1e1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

core/object/object.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,10 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
12211221
uint32_t *slot_flags = slot_flags_stack;
12221222
uint32_t slot_count = 0;
12231223

1224+
// If this is a ref-counted object, prevent it from being destroyed during signal emission,
1225+
// which is needed in certain edge cases; e.g., GH-73889 and GH-109471.
1226+
Ref<RefCounted> extra_rc = Ref<RefCounted>(Object::cast_to<RefCounted>(this));
1227+
12241228
{
12251229
OBJ_SIGNAL_LOCK
12261230

@@ -1235,10 +1239,6 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
12351239
return ERR_UNAVAILABLE;
12361240
}
12371241

1238-
// If this is a ref-counted object, prevent it from being destroyed during signal emission,
1239-
// which is needed in certain edge cases; e.g., https://github.com/godotengine/godot/issues/73889.
1240-
Ref<RefCounted> rc = Ref<RefCounted>(Object::cast_to<RefCounted>(this));
1241-
12421242
if (s->slot_map.size() > MAX_SLOTS_ON_STACK) {
12431243
slot_callables = (Callable *)memalloc(sizeof(Callable) * s->slot_map.size());
12441244
slot_flags = (uint32_t *)memalloc(sizeof(uint32_t) * s->slot_map.size());
@@ -1320,6 +1320,8 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
13201320
memfree(slot_flags);
13211321
}
13221322

1323+
(void)extra_rc; // Ensure it's scoped to the function so it lives up to the end.
1324+
13231325
return err;
13241326
}
13251327

0 commit comments

Comments
 (0)