summaryrefslogtreecommitdiff
path: root/modules/gdnative/gdnative.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdnative/gdnative.cpp')
-rw-r--r--modules/gdnative/gdnative.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp
index e8278825bc..ee9e71d4a0 100644
--- a/modules/gdnative/gdnative.cpp
+++ b/modules/gdnative/gdnative.cpp
@@ -48,7 +48,7 @@ static const bool default_reloadable = true;
// Defined in gdnative_api_struct.gen.cpp
extern const godot_gdnative_core_api_struct api_struct;
-Map<String, Vector<Ref<GDNative> > > *GDNativeLibrary::loaded_libraries = NULL;
+Map<String, Vector<Ref<GDNative> > > GDNativeLibrary::loaded_libraries;
GDNativeLibrary::GDNativeLibrary() {
config_file.instance();
@@ -57,10 +57,6 @@ GDNativeLibrary::GDNativeLibrary() {
load_once = default_load_once;
singleton = default_singleton;
reloadable = default_reloadable;
-
- if (GDNativeLibrary::loaded_libraries == NULL) {
- GDNativeLibrary::loaded_libraries = memnew((Map<String, Vector<Ref<GDNative> > >));
- }
}
GDNativeLibrary::~GDNativeLibrary() {
@@ -243,7 +239,7 @@ void GDNativeLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_symbol_prefix", "symbol_prefix"), &GDNativeLibrary::set_symbol_prefix);
ClassDB::bind_method(D_METHOD("set_reloadable", "reloadable"), &GDNativeLibrary::set_reloadable);
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "config_file", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"), "set_config_file", "get_config_file");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "config_file", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile", 0), "set_config_file", "get_config_file");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "load_once"), "set_load_once", "should_load_once");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "singleton"), "set_singleton", "is_singleton");
@@ -272,8 +268,7 @@ void GDNative::_bind_methods() {
}
void GDNative::set_library(Ref<GDNativeLibrary> p_library) {
- ERR_EXPLAIN("Tried to change library of GDNative when it is already set");
- ERR_FAIL_COND(library.is_valid());
+ ERR_FAIL_COND_MSG(library.is_valid(), "Tried to change library of GDNative when it is already set.");
library = p_library;
}
@@ -318,10 +313,10 @@ bool GDNative::initialize() {
#endif
if (library->should_load_once()) {
- if (GDNativeLibrary::loaded_libraries->has(lib_path)) {
+ if (GDNativeLibrary::loaded_libraries.has(lib_path)) {
// already loaded. Don't load again.
// copy some of the stuff instead
- this->native_handle = (*GDNativeLibrary::loaded_libraries)[lib_path][0]->native_handle;
+ this->native_handle = GDNativeLibrary::loaded_libraries[lib_path][0]->native_handle;
initialized = true;
return true;
}
@@ -344,7 +339,7 @@ bool GDNative::initialize() {
if (err || !library_init) {
OS::get_singleton()->close_dynamic_library(native_handle);
native_handle = NULL;
- ERR_PRINT("Failed to obtain godot_gdnative_init symbol");
+ ERR_PRINTS("Failed to obtain " + library->get_symbol_prefix() + "gdnative_init symbol");
return false;
}
@@ -377,11 +372,11 @@ bool GDNative::initialize() {
initialized = true;
- if (library->should_load_once() && !GDNativeLibrary::loaded_libraries->has(lib_path)) {
+ if (library->should_load_once() && !GDNativeLibrary::loaded_libraries.has(lib_path)) {
Vector<Ref<GDNative> > gdnatives;
gdnatives.resize(1);
gdnatives.write[0] = Ref<GDNative>(this);
- GDNativeLibrary::loaded_libraries->insert(lib_path, gdnatives);
+ GDNativeLibrary::loaded_libraries.insert(lib_path, gdnatives);
}
return true;
@@ -395,7 +390,7 @@ bool GDNative::terminate() {
}
if (library->should_load_once()) {
- Vector<Ref<GDNative> > *gdnatives = &(*GDNativeLibrary::loaded_libraries)[library->get_current_library_path()];
+ Vector<Ref<GDNative> > *gdnatives = &GDNativeLibrary::loaded_libraries[library->get_current_library_path()];
if (gdnatives->size() > 1) {
// there are other GDNative's still using this library, so we actually don't terminate
gdnatives->erase(Ref<GDNative>(this));
@@ -404,8 +399,8 @@ bool GDNative::terminate() {
} else if (gdnatives->size() == 1) {
// we're the last one, terminate!
gdnatives->clear();
- // wew this looks scary, but all it does is remove the entry completely
- GDNativeLibrary::loaded_libraries->erase(GDNativeLibrary::loaded_libraries->find(library->get_current_library_path()));
+ // whew this looks scary, but all it does is remove the entry completely
+ GDNativeLibrary::loaded_libraries.erase(GDNativeLibrary::loaded_libraries.find(library->get_current_library_path()));
}
}