Dont call nativescript callbacks if lib is not initialized

This commit is contained in:
Ruslan Mustakov 2017-08-04 21:17:33 +07:00
parent 7ac50b523b
commit d71171026f
3 changed files with 17 additions and 10 deletions

View file

@ -155,7 +155,6 @@ String GDNativeLibrary::get_active_library_path() const {
} }
GDNative::GDNative() { GDNative::GDNative() {
initialized = false;
native_handle = NULL; native_handle = NULL;
} }
@ -219,6 +218,9 @@ bool GDNative::initialize() {
library_init); library_init);
if (err || !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; return false;
} }
@ -272,7 +274,11 @@ bool GDNative::terminate() {
OS::get_singleton()->close_dynamic_library(native_handle); OS::get_singleton()->close_dynamic_library(native_handle);
native_handle = NULL; 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) { void GDNativeCallRegistry::register_native_call_type(StringName p_call_type, native_call_cb p_callback) {

View file

@ -117,7 +117,6 @@ class GDNative : public Reference {
GDCLASS(GDNative, Reference) GDCLASS(GDNative, Reference)
Ref<GDNativeLibrary> library; Ref<GDNativeLibrary> library;
bool initialized;
// TODO(karroffel): different platforms? WASM???? // TODO(karroffel): different platforms? WASM????
void *native_handle; void *native_handle;

View file

@ -1055,13 +1055,15 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) {
void NativeScriptLanguage::call_libraries_cb(const StringName &name) { 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 // library_gdnatives is modified only from the main thread, so it's safe not to use mutex here
for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) { for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
L->get()->call_native_raw( if (L->get()->is_initialized()) {
_noarg_call_type, L->get()->call_native_raw(
name, _noarg_call_type,
NULL, name,
0, NULL,
NULL, 0,
NULL); NULL,
NULL);
}
} }
} }