Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Remove extra reference in Object::emit_signalp

NoctemCatb0976cd66ff9
diff --git a/core/object/object.cpp b/core/object/object.cpp
index ab3a4742667..d7bb0d59e48 100644
--- a/core/object/object.cpp
+++ b/core/object/object.cpp
@@ -1195,16 +1195,11 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
OBJ_DEBUG_LOCK
- // If this is a ref-counted object, prevent it from being destroyed during signal
- // emission, which is needed in certain edge cases; e.g., GH-73889 and GH-109471.
- // Moreover, since signals can be emitted from constructors (classic example being
- // notify_property_list_changed), we must be careful not to do the ref init ourselves,
- // which would lead to the object being destroyed at the end of this function.
- bool pending_unref = Object::cast_to<RefCounted>(this) ? ((RefCounted *)this)->reference() : false;
-
Error err = OK;
- Vector<const Variant *> append_source_mem;
+ LocalVector<const Variant *> append_source_mem;
+ // If this is a ref-counted object, `source` also prevents it from being destroyed during
+ // signal emission, which is needed in certain edge cases; e.g., GH-73889 and GH-109471.
Variant source = this;
for (uint32_t i = 0; i < slot_count; ++i) {
@@ -1225,7 +1220,7 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
int source_index = p_argcount - callable.get_unbound_arguments_count();
if (source_index >= 0) {
append_source_mem.resize(p_argcount + 1);
- const Variant **args_mem = append_source_mem.ptrw();
+ const Variant **args_mem = append_source_mem.ptr();
for (int j = 0; j < source_index; j++) {
args_mem[j] = p_args[j];
@@ -1283,14 +1278,7 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
memfree(slot_flags);
}
- if (pending_unref) {
- // We have to do the same Ref<T> would do. We can't just use Ref<T>
- // because it would do the init ref logic, which is something this function
- // shouldn't do, as explained above.
- if (((RefCounted *)this)->unreference()) {
- memdelete(this);
- }
- }
+ (void)source; // Ensure it's scoped to the function so it lives up to the end.
return err;
}