summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/gdnative/gdnative.cpp10
-rw-r--r--modules/gdnative/gdnative.h1
-rw-r--r--modules/gdnative/godot/dictionary.cpp3
-rw-r--r--modules/gdnative/godot/node_path.cpp2
-rw-r--r--modules/gdnative/godot/variant.cpp1
-rw-r--r--modules/nativescript/nativescript.cpp54
-rw-r--r--modules/nativescript/nativescript.h12
-rw-r--r--modules/nativescript/register_types.cpp12
-rw-r--r--modules/visual_script/visual_script_nodes.cpp2
9 files changed, 46 insertions, 51 deletions
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp
index 158f7fd94d..07dba921b1 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 f02741f4e3..b03866f432 100644
--- a/modules/gdnative/gdnative.h
+++ b/modules/gdnative/gdnative.h
@@ -117,7 +117,6 @@ class GDNative : public Reference {
GDCLASS(GDNative, Reference)
Ref<GDNativeLibrary> library;
- bool initialized;
// TODO(karroffel): different platforms? WASM????
void *native_handle;
diff --git a/modules/gdnative/godot/dictionary.cpp b/modules/gdnative/godot/dictionary.cpp
index ce402fa008..b92c8125bb 100644
--- a/modules/gdnative/godot/dictionary.cpp
+++ b/modules/gdnative/godot/dictionary.cpp
@@ -29,9 +29,10 @@
/*************************************************************************/
#include <godot/dictionary.h>
+#include "core/variant.h"
+
#include "core/dictionary.h"
#include "core/io/json.h"
-#include "core/variant.h"
#ifdef __cplusplus
extern "C" {
diff --git a/modules/gdnative/godot/node_path.cpp b/modules/gdnative/godot/node_path.cpp
index e718a9e55f..f4179361be 100644
--- a/modules/gdnative/godot/node_path.cpp
+++ b/modules/gdnative/godot/node_path.cpp
@@ -29,7 +29,7 @@
/*************************************************************************/
#include <godot/node_path.h>
-#include "core/path_db.h"
+#include "core/node_path.h"
#include "core/variant.h"
#ifdef __cplusplus
diff --git a/modules/gdnative/godot/variant.cpp b/modules/gdnative/godot/variant.cpp
index 506614583c..d814ef913c 100644
--- a/modules/gdnative/godot/variant.cpp
+++ b/modules/gdnative/godot/variant.cpp
@@ -433,7 +433,6 @@ godot_variant GDAPI godot_variant_call(godot_variant *p_self, const godot_string
Variant *dest = (Variant *)&raw_dest;
Variant::CallError error;
memnew_placement_custom(dest, Variant, Variant(self->call(*method, args, p_argcount, error)));
- *dest = self->call(StringName(*method), args, p_argcount, r_error);
if (r_error) {
r_error->error = (godot_variant_call_error_error)error.error;
r_error->argument = error.argument;
diff --git a/modules/nativescript/nativescript.cpp b/modules/nativescript/nativescript.cpp
index ad746c9546..fb334e573c 100644
--- a/modules/nativescript/nativescript.cpp
+++ b/modules/nativescript/nativescript.cpp
@@ -1052,9 +1052,23 @@ void NativeScriptLanguage::unregister_script(NativeScript *script) {
#endif
}
-#ifndef NO_THREADS
+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<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
+ if (L->get()->is_initialized()) {
+ L->get()->call_native_raw(
+ _noarg_call_type,
+ name,
+ NULL,
+ 0,
+ NULL,
+ NULL);
+ }
+ }
+}
void NativeScriptLanguage::frame() {
+#ifndef NO_THREADS
if (has_objects_to_register) {
MutexLock lock(mutex);
for (Set<Ref<GDNativeLibrary> >::Element *L = libs_to_init.front(); L; L = L->next()) {
@@ -1067,44 +1081,18 @@ void NativeScriptLanguage::frame() {
scripts_to_register.clear();
has_objects_to_register = false;
}
+#endif
+ call_libraries_cb(_frame_call_name);
}
+#ifndef NO_THREADS
+
void NativeScriptLanguage::thread_enter() {
- Vector<Ref<GDNative> > libs;
- {
- MutexLock lock(mutex);
- for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
- libs.push_back(L->get());
- }
- }
- for (int i = 0; i < libs.size(); ++i) {
- libs[i]->call_native_raw(
- _thread_cb_call_type,
- _thread_enter_call_name,
- NULL,
- 0,
- NULL,
- NULL);
- }
+ call_libraries_cb(_thread_enter_call_name);
}
void NativeScriptLanguage::thread_exit() {
- Vector<Ref<GDNative> > libs;
- {
- MutexLock lock(mutex);
- for (Map<String, Ref<GDNative> >::Element *L = library_gdnatives.front(); L; L = L->next()) {
- libs.push_back(L->get());
- }
- }
- for (int i = 0; i < libs.size(); ++i) {
- libs[i]->call_native_raw(
- _thread_cb_call_type,
- _thread_exit_call_name,
- NULL,
- 0,
- NULL,
- NULL);
- }
+ call_libraries_cb(_thread_exit_call_name);
}
#endif // NO_THREADS
diff --git a/modules/nativescript/nativescript.h b/modules/nativescript/nativescript.h
index 95b4954171..c60effd0c1 100644
--- a/modules/nativescript/nativescript.h
+++ b/modules/nativescript/nativescript.h
@@ -220,7 +220,10 @@ private:
void register_script(NativeScript *script);
void unregister_script(NativeScript *script);
+ void call_libraries_cb(const StringName &name);
+
public:
+ // These two maps must only be touched on the main thread
Map<String, Map<StringName, NativeScriptDesc> > library_classes;
Map<String, Ref<GDNative> > library_gdnatives;
@@ -229,9 +232,14 @@ public:
const StringName _init_call_type = "nativescript_init";
const StringName _init_call_name = "godot_nativescript_init";
- const StringName _thread_cb_call_type = "godot_nativescript_thread_cb";
+ const StringName _noarg_call_type = "nativescript_no_arg";
+
+ const StringName _frame_call_name = "godot_nativescript_frame";
+
+#ifndef NO_THREADS
const StringName _thread_enter_call_name = "godot_nativescript_thread_enter";
const StringName _thread_exit_call_name = "godot_nativescript_thread_exit";
+#endif
NativeScriptLanguage();
~NativeScriptLanguage();
@@ -245,9 +253,9 @@ public:
#ifndef NO_THREADS
virtual void thread_enter();
virtual void thread_exit();
+#endif
virtual void frame();
-#endif
virtual String get_name() const;
virtual void init();
diff --git a/modules/nativescript/register_types.cpp b/modules/nativescript/register_types.cpp
index dfa16d8a2a..c28b982884 100644
--- a/modules/nativescript/register_types.cpp
+++ b/modules/nativescript/register_types.cpp
@@ -62,13 +62,11 @@ void init_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p
fn(args[0]);
}
-#ifndef NO_THREADS
-
typedef void (*native_script_empty_callback)();
-void thread_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p_num_args, void **args, void *r_ret) {
+void noarg_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int p_num_args, void **args, void *r_ret) {
if (p_handle == NULL) {
- ERR_PRINT("No valid library handle, can't call nativescript thread enter/exit callback");
+ ERR_PRINT("No valid library handle, can't call nativescript callback");
return;
}
@@ -87,8 +85,6 @@ void thread_call_cb(void *p_handle, godot_string *p_proc_name, void *p_data, int
fn();
}
-#endif // NO_THREADS
-
ResourceFormatLoaderNativeScript *resource_loader_gdns = NULL;
ResourceFormatSaverNativeScript *resource_saver_gdns = NULL;
@@ -100,9 +96,7 @@ void register_nativescript_types() {
ScriptServer::register_language(native_script_language);
GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_init_call_type, init_call_cb);
-#ifndef NO_THREADS
- GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_thread_cb_call_type, thread_call_cb);
-#endif
+ GDNativeCallRegistry::singleton->register_native_raw_call_type(native_script_language->_noarg_call_type, noarg_call_cb);
resource_saver_gdns = memnew(ResourceFormatSaverNativeScript);
ResourceSaver::add_resource_format_saver(resource_saver_gdns);
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp
index 69aa10ebca..d5d8b8fe6e 100644
--- a/modules/visual_script/visual_script_nodes.cpp
+++ b/modules/visual_script/visual_script_nodes.cpp
@@ -2798,7 +2798,7 @@ public:
r_error.error = Variant::CallError::CALL_ERROR_INVALID_METHOD;
return 0;
}
- *p_outputs[0] = subcall->call(VisualScriptLanguage::singleton->_subcall, p_inputs, input_args, r_error_str);
+ *p_outputs[0] = subcall->call(VisualScriptLanguage::singleton->_subcall, p_inputs, input_args, r_error);
return 0;
}
};