C#: Fix RefCounted not disposed correctly in certain case.

This commit is contained in:
Zae 2025-01-02 05:05:43 +08:00
parent 2582793d40
commit 05b840a815

View file

@ -203,6 +203,11 @@ void godotsharp_internal_refcounted_disposed(Object *p_ptr, GCHandleIntPtr p_gch
CSharpScriptBinding &script_binding = ((RBMap<Object *, CSharpScriptBinding>::Element *)data)->get();
if (script_binding.inited) {
if (!script_binding.gchandle.is_released()) {
if (rc->get_reference_count() == 1 && script_binding.gchandle.is_weak()) {
// The GCHandle is just swapped, so get the swapped handle to release
// See: CSharpLanguage::_instance_binding_reference_callback(void *p_token, void *p_binding, GDExtensionBool p_reference)
p_gchandle_to_free = script_binding.gchandle.get_intptr();
}
CSharpLanguage::release_binding_gchandle_thread_safe(p_gchandle_to_free, script_binding);
}
}