summaryrefslogtreecommitdiffstats
path: root/modules/mono/managed_callable.cpp
diff options
context:
space:
mode:
authorPatrick Dawson <pat@dw.is>2022-09-30 18:22:11 +0200
committerPatrick Dawson <pat@dw.is>2022-10-01 02:09:58 +0200
commit161f295f52d21dea940d7c06e5f83a14beefb4c9 (patch)
tree72d3dcc6075b0980bf67c76ae6b5c40b230092dc /modules/mono/managed_callable.cpp
parente69b7083d45c5d8698508cce7086d361c4b1f44c (diff)
downloadredot-engine-161f295f52d21dea940d7c06e5f83a14beefb4c9.tar.gz
ManagedCallable: use delegate target instead of middleman when possible
If the delegate target is an Object, the connected signal will be registered in that object instead of the middleman. So when that object is destroyed, the signal will be properly disconnected.
Diffstat (limited to 'modules/mono/managed_callable.cpp')
-rw-r--r--modules/mono/managed_callable.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/modules/mono/managed_callable.cpp b/modules/mono/managed_callable.cpp
index 9305dc645a..0c2c533090 100644
--- a/modules/mono/managed_callable.cpp
+++ b/modules/mono/managed_callable.cpp
@@ -79,7 +79,9 @@ CallableCustom::CompareLessFunc ManagedCallable::get_compare_less_func() const {
}
ObjectID ManagedCallable::get_object() const {
- // TODO: If the delegate target extends Godot.Object, use that instead!
+ if (object_id != ObjectID()) {
+ return object_id;
+ }
return CSharpLanguage::get_singleton()->get_managed_callable_middleman()->get_instance_id();
}
@@ -104,7 +106,7 @@ void ManagedCallable::release_delegate_handle() {
// Why you do this clang-format...
/* clang-format off */
-ManagedCallable::ManagedCallable(GCHandleIntPtr p_delegate_handle) : delegate_handle(p_delegate_handle) {
+ManagedCallable::ManagedCallable(GCHandleIntPtr p_delegate_handle, ObjectID p_object_id) : delegate_handle(p_delegate_handle), object_id(p_object_id) {
#ifdef GD_MONO_HOT_RELOAD
{
MutexLock lock(instances_mutex);