From 9ee3d9aeb117fb24b727ae36eaa242f4ba69400e Mon Sep 17 00:00:00 2001 From: follower Date: Wed, 24 Jun 2020 14:12:33 +1200 Subject: [PATCH] Update to `godot-cpp` 9eceb16f0553884094d0f659461649be5d333866. As of `godot-cpp` 9eceb16f0553884094d0f659461649be5d333866 a number of fixes have been incorporated that mean `Ref<>`s are no longer leaked and `PoolByteArray`/`PoolStringArray`s are also no longer leaked when passed as arguments to GDNative functions. The one(?) downside is that the `Ref<>` workaround that *was* necessary...now causes a crash. *sigh* Originally I thought `godot-cpp` latest (~3.2 but it's not on the 3.2 branch, yet) didn't work with Godot 3.1.x but it turned out that the "mysterious load error" that occurred was Godot not finding the test script! Apparently the "current directory" is calculated different in Godot 3.1.x than 3.2.x but the error returned wasn't stated as "file not found". Because of what I thought was an incompatibility I figured out how to get `godot-cpp` 3.1 to also not leak memory and while that's not actually necessary now I thought I'd at least commit it, at least temporarily, hence the conditionals. (Not yet committed.) But the upshot is, this commit will probably be broken or leak memory when compiled against `godot-cpp` 3.1 but should be good for `godot-cpp` @ the mentioned ref. More details: --- src/foreigner.cpp | 8 ++++++++ src/foreigner.h | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/foreigner.cpp b/src/foreigner.cpp index d70d9343..b45f3afa 100644 --- a/src/foreigner.cpp +++ b/src/foreigner.cpp @@ -24,7 +24,11 @@ Ref Foreigner::new_buffer(uint32_t size_in_bytes) { ForeignBuffer *the_buffer = ForeignBuffer::_new(); the_buffer->_init_buffer(size_in_bytes); +#if defined(TARGET_GODOT_CPP_3_2_LATEST) + Ref ref = Ref(the_buffer); +#else Ref ref = Ref::__internal_constructor(the_buffer); +#endif return ref; } @@ -57,7 +61,11 @@ Ref Foreigner::open(String path) { } ForeignLibrary *library = ForeignLibrary::_new(); +#if defined(TARGET_GODOT_CPP_3_2_LATEST) + Ref ref = Ref(library); +#else Ref ref = Ref::__internal_constructor(library); +#endif library->setHandle(handle); return ref; } diff --git a/src/foreigner.h b/src/foreigner.h index 5447cf78..fda988d2 100644 --- a/src/foreigner.h +++ b/src/foreigner.h @@ -10,6 +10,8 @@ #include "foreignbuffer.h" +#define TARGET_GODOT_CPP_3_2_LATEST // 9eceb16f0553884094d0f659461649be5d333866 + namespace godot { class Foreigner : public Reference {