From d71171026f321b635b93e1c4e026f791ff51d324 Mon Sep 17 00:00:00 2001 From: Ruslan Mustakov Date: Fri, 4 Aug 2017 21:17:33 +0700 Subject: [PATCH] Dont call nativescript callbacks if lib is not initialized --- modules/gdnative/gdnative.cpp | 10 ++++++++-- modules/gdnative/gdnative.h | 1 - modules/nativescript/nativescript.cpp | 16 +++++++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 158f7fd94d8..07dba921b14 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -155,7 +155,6 @@ String GDNativeLibrary::get_active_library_path() const { } GDNative::GDNative() { - initialized = false; native_handle = NULL; } @@ -219,6 +218,9 @@ bool GDNative::initialize() { library_init); if (err || !library_init) { + OS::get_singleton()->close_dynamic_library(native_handle); + native_handle = NULL; + ERR_PRINT("Failed to obtain godot_gdnative_init symbol"); return false; } @@ -272,7 +274,11 @@ bool GDNative::terminate() { OS::get_singleton()->close_dynamic_library(native_handle); native_handle = NULL; - return false; + return true; +} + +bool GDNative::is_initialized() { + return (native_handle != NULL); } void GDNativeCallRegistry::register_native_call_type(StringName p_call_type, native_call_cb p_callback) { diff --git a/modules/gdnative/gdnative.h b/modules/gdnative/gdnative.h index f02741f4e37..b03866f4327 100644 --- a/modules/gdnative/gdnative.h +++ b/modules/gdnative/gdnative.h @@ -117,7 +117,6 @@ class GDNative : public Reference { GDCLASS(GDNative, Reference) Ref library; - bool initialized; // TODO(karroffel): different platforms? WASM???? void *native_handle; diff --git a/modules/nativescript/nativescript.cpp b/modules/nativescript/nativescript.cpp index 226b5effa9f..fb334e573c9 100644 --- a/modules/nativescript/nativescript.cpp +++ b/modules/nativescript/nativescript.cpp @@ -1055,13 +1055,15 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) { void NativeScriptLanguage::call_libraries_cb(const StringName &name) { // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here for (Map >::Element *L = library_gdnatives.front(); L; L = L->next()) { - L->get()->call_native_raw( - _noarg_call_type, - name, - NULL, - 0, - NULL, - NULL); + if (L->get()->is_initialized()) { + L->get()->call_native_raw( + _noarg_call_type, + name, + NULL, + 0, + NULL, + NULL); + } } }