1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Fix edge cases of object lifetime when signals involved

This commit is contained in:
Pedro J. Estébanez
2023-04-11 17:20:03 +02:00
parent 59b8c70007
commit 2f4168daeb
5 changed files with 30 additions and 1 deletions

View File

@@ -1013,6 +1013,10 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
return ERR_UNAVAILABLE;
}
// If this is a ref-counted object, prevent it from being destroyed during signal emission,
// which is needed in certain edge cases; e.g., https://github.com/godotengine/godot/issues/73889.
Ref<RefCounted> rc = Ref<RefCounted>(Object::cast_to<RefCounted>(this));
List<_ObjectSignalDisconnectData> disconnect_data;
//copy on write will ensure that disconnecting the signal or even deleting the object will not affect the signal calling.