MCPcopy Create free account
hub / github.com/borndotcom/react-native-godot / get_or_create_instance

Method get_or_create_instance

android/src/main/cpp/GodotModule.cpp:248–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

246}
247
248godot::GodotInstance *GodotModule::get_or_create_instance(std::vector<std::string> args) {
249 AndroidPlatformData *data = static_cast<AndroidPlatformData *>(_data);
250
251 // Make sure that we only run this method once at a time.
252 std::lock_guard createLock(data->createMutex);
253
254 {
255 std::lock_guard lock(_mutex);
256 if (_instance) {
257 return _instance;
258 }
259 }
260
261 void *handle = nullptr;
262 if (!data->func_libgodot_create_godot_instance_android) {
263 libgodot_create_godot_instance_android_type func_libgodot_create_godot_instance_android = nullptr;
264#ifndef LIBGODOT_STATIC
265 handle = dlopen("libgodot_android.so", RTLD_LAZY | RTLD_LOCAL);
266
267 if (handle == nullptr) {
268 LOGI("Unable to open libgodot_android.so: %s", dlerror());
269 return nullptr;
270 }
271 func_libgodot_create_godot_instance_android = (libgodot_create_godot_instance_android_type)dlsym(handle, "libgodot_create_godot_instance_android");
272
273 if (func_libgodot_create_godot_instance_android == nullptr) {
274 LOGE("Unable to load libgodot_create_godot_instance symbol: %s", dlerror());
275 dlclose(handle);
276 handle = nullptr;
277 return nullptr;
278 }
279#else
280 func_libgodot_create_godot_instance_android = libgodot_create_godot_instance_android;
281#endif
282 {
283 std::lock_guard lock(_mutex);
284 data->func_libgodot_create_godot_instance_android = func_libgodot_create_godot_instance_android;
285 }
286 }
287
288 std::vector<std::string> cmdline{ "apk" };
289 for (std::string arg : args) {
290 cmdline.push_back(arg);
291 }
292
293 std::vector<const char *> cargs{};
294 for (const std::string &arg : cmdline) {
295 cargs.push_back(arg.c_str());
296 }
297
298 GDExtensionObjectPtr instance_ptr = nullptr;
299 {
300 std::lock_guard lock(_mutex);
301 instance_ptr = data->func_libgodot_create_godot_instance_android(
302 cargs.size(),
303 (char **)cargs.data(),
304 gdextension_default_init,
305 LibGodot::get_jni_env(),

Callers 1

createNativeGodotModuleFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected