ソースを参照

Merge pull request #101006 from zaevi/fix_csharp_refcounted_dispose

C#: Fix `RefCounted` not disposed correctly in certain case
Thaddeus Crews 2 ヶ月 前
コミット
f8b2f1bc82
1 ファイル変更5 行追加0 行削除
  1. 5 0
      modules/mono/glue/runtime_interop.cpp

+ 5 - 0
modules/mono/glue/runtime_interop.cpp

@@ -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);
 				}
 			}