Skip to content

Commit f8b2f1b

Browse files
committed
Merge pull request #101006 from zaevi/fix_csharp_refcounted_dispose
C#: Fix `RefCounted` not disposed correctly in certain case
2 parents bad29ef + 05b840a commit f8b2f1b

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

modules/mono/glue/runtime_interop.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ void godotsharp_internal_refcounted_disposed(Object *p_ptr, GCHandleIntPtr p_gch
203203
CSharpScriptBinding &script_binding = ((RBMap<Object *, CSharpScriptBinding>::Element *)data)->get();
204204
if (script_binding.inited) {
205205
if (!script_binding.gchandle.is_released()) {
206+
if (rc->get_reference_count() == 1 && script_binding.gchandle.is_weak()) {
207+
// The GCHandle is just swapped, so get the swapped handle to release
208+
// See: CSharpLanguage::_instance_binding_reference_callback(void *p_token, void *p_binding, GDExtensionBool p_reference)
209+
p_gchandle_to_free = script_binding.gchandle.get_intptr();
210+
}
206211
CSharpLanguage::release_binding_gchandle_thread_safe(p_gchandle_to_free, script_binding);
207212
}
208213
}

0 commit comments

Comments
 (0)