From 3747ffe8716dd51a739ef6d6881e819d1750decc Mon Sep 17 00:00:00 2001 From: Fredia Huya-Kouadio Date: Tue, 14 Apr 2020 12:28:27 -0700 Subject: [PATCH] Fix godot-cpp types registration A initialization bug was causing the registration to occur prior to a key required field being set (see https://github.com/GodotNativeTools/godot-cpp/issues/394#issuecomment-613636985 for more details). Fixes #394 --- src/core/GodotGlobal.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/GodotGlobal.cpp b/src/core/GodotGlobal.cpp index 83cc6952..c7cae20d 100644 --- a/src/core/GodotGlobal.cpp +++ b/src/core/GodotGlobal.cpp @@ -140,6 +140,13 @@ void Godot::gdnative_init(godot_gdnative_init_options *options) { } } + // Initialize the `language_index` here since `__register_types()` makes use of it. + godot_instance_binding_functions binding_funcs = {}; + binding_funcs.alloc_instance_binding_data = wrapper_create; + binding_funcs.free_instance_binding_data = wrapper_destroy; + + godot::_RegisterState::language_index = godot::nativescript_1_1_api->godot_nativescript_register_instance_binding_data_functions(binding_funcs); + // register these now ___register_types(); ___init_method_bindings(); @@ -155,12 +162,6 @@ void Godot::gdnative_profiling_add_data(const char *p_signature, uint64_t p_time void Godot::nativescript_init(void *handle) { godot::_RegisterState::nativescript_handle = handle; - - godot_instance_binding_functions binding_funcs = {}; - binding_funcs.alloc_instance_binding_data = wrapper_create; - binding_funcs.free_instance_binding_data = wrapper_destroy; - - godot::_RegisterState::language_index = godot::nativescript_1_1_api->godot_nativescript_register_instance_binding_data_functions(binding_funcs); } void Godot::nativescript_terminate(void *handle) {