diff --git a/src/io/assets_android.cpp b/src/io/assets_android.cpp index bf6496e14..06b27adfe 100644 --- a/src/io/assets_android.cpp +++ b/src/io/assets_android.cpp @@ -659,10 +659,10 @@ std::string AssetsAndroid::getDataPath() { Log::warn("AssetsAndroid", "Cannot use standard data dir"); - if (global_android_app) + if (global_android_activity) { AndroidApplicationInfo application_info = - CIrrDeviceAndroid::getApplicationInfo(global_android_app->activity); + CIrrDeviceAndroid::getApplicationInfo(global_android_activity); data_path = application_info.data_dir; } @@ -688,10 +688,10 @@ std::string AssetsAndroid::getLibPath() #ifdef ANDROID std::string lib_path; - if (global_android_app) + if (global_android_activity) { AndroidApplicationInfo application_info = - CIrrDeviceAndroid::getApplicationInfo(global_android_app->activity); + CIrrDeviceAndroid::getApplicationInfo(global_android_activity); lib_path = application_info.native_lib_dir; } diff --git a/src/main_android.cpp b/src/main_android.cpp index 7d57727f7..6e1bdf94d 100644 --- a/src/main_android.cpp +++ b/src/main_android.cpp @@ -27,7 +27,16 @@ extern int main(int argc, char *argv[]); -struct android_app* global_android_app; +struct android_app* global_android_app = NULL; +ANativeActivity* global_android_activity = NULL; + +extern "C" +{ +void set_global_android_activity(ANativeActivity* activity) +{ + global_android_activity = activity; +} +} void override_default_params_for_mobile() { @@ -92,6 +101,7 @@ void android_main(struct android_app* app) Log::info("AndroidMain", "Loading application..."); global_android_app = app; + global_android_activity = app->activity; // Initialize global Android window state variables CIrrDeviceAndroid::onCreate(); diff --git a/src/main_android.hpp b/src/main_android.hpp index f3d62ad88..81869e2a7 100644 --- a/src/main_android.hpp +++ b/src/main_android.hpp @@ -23,7 +23,7 @@ #include "../../../lib/irrlicht/source/Irrlicht/stk_android_native_app_glue.h" extern struct android_app* global_android_app; - +extern ANativeActivity* global_android_activity; #endif #endif \ No newline at end of file diff --git a/src/utils/separate_process.cpp b/src/utils/separate_process.cpp index 71724046e..13b34053c 100644 --- a/src/utils/separate_process.cpp +++ b/src/utils/separate_process.cpp @@ -44,6 +44,7 @@ #include #include +#include "main_android.hpp" #include "io/assets_android.hpp" #endif @@ -387,6 +388,21 @@ bool SeparateProcess::createChildProcess(const std::string& exe, m_child_handle = NULL; return false; } + + typedef void (*set_activity_proc_t)(ANativeActivity*); + set_activity_proc_t set_activity_proc = + (set_activity_proc_t)dlsym(m_child_handle, "set_global_android_activity"); + + if (set_activity_proc == NULL) + { + Log::error("SeparateProcess", "Error: Cannot get handle to " + "set_global_android_activity()"); + dlclose(m_child_handle); + m_child_handle = NULL; + return false; + } + + set_activity_proc(global_android_activity); const std::string exe_file = StringUtils::getBasename(exe); auto rest_argv = StringUtils::split(argument, ' ');