You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-22 15:06:45 +00:00
Fix/workaround for issue #21667
When a Reference managed instance is garbage collected and its finalizer is called, it could happen that the native instance is referenced once again before the finalizer can unreference and memdelete it. The workaround is to create a new managed instance when this happens (at least for now).
This commit is contained in:
@@ -32,24 +32,34 @@
|
||||
|
||||
#include "mono_gd/gd_mono.h"
|
||||
|
||||
uint32_t MonoGCHandle::make_strong_handle(MonoObject *p_object) {
|
||||
uint32_t MonoGCHandle::new_strong_handle(MonoObject *p_object) {
|
||||
|
||||
return mono_gchandle_new(p_object, /* pinned: */ false);
|
||||
}
|
||||
|
||||
uint32_t MonoGCHandle::make_weak_handle(MonoObject *p_object) {
|
||||
uint32_t MonoGCHandle::new_strong_handle_pinned(MonoObject *p_object) {
|
||||
|
||||
return mono_gchandle_new(p_object, /* pinned: */ true);
|
||||
}
|
||||
|
||||
uint32_t MonoGCHandle::new_weak_handle(MonoObject *p_object) {
|
||||
|
||||
return mono_gchandle_new_weakref(p_object, /* track_resurrection: */ false);
|
||||
}
|
||||
|
||||
void MonoGCHandle::free_handle(uint32_t p_gchandle) {
|
||||
|
||||
mono_gchandle_free(p_gchandle);
|
||||
}
|
||||
|
||||
Ref<MonoGCHandle> MonoGCHandle::create_strong(MonoObject *p_object) {
|
||||
|
||||
return memnew(MonoGCHandle(make_strong_handle(p_object), STRONG_HANDLE));
|
||||
return memnew(MonoGCHandle(new_strong_handle(p_object), STRONG_HANDLE));
|
||||
}
|
||||
|
||||
Ref<MonoGCHandle> MonoGCHandle::create_weak(MonoObject *p_object) {
|
||||
|
||||
return memnew(MonoGCHandle(make_weak_handle(p_object), WEAK_HANDLE));
|
||||
return memnew(MonoGCHandle(new_weak_handle(p_object), WEAK_HANDLE));
|
||||
}
|
||||
|
||||
void MonoGCHandle::release() {
|
||||
@@ -59,7 +69,7 @@ void MonoGCHandle::release() {
|
||||
#endif
|
||||
|
||||
if (!released && GDMono::get_singleton()->is_runtime_initialized()) {
|
||||
mono_gchandle_free(handle);
|
||||
free_handle(handle);
|
||||
released = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user