From d877ca1d3a33deb9079e9e2eba9cc3dbadf1ae28 Mon Sep 17 00:00:00 2001 From: Alan Jeffrey Date: Thu, 6 Jun 2019 12:34:52 -0500 Subject: [PATCH] Fix the magicleap app to work in LuminOS 0.96 --- demo/magicleap/src/main.cpp | 49 +++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/demo/magicleap/src/main.cpp b/demo/magicleap/src/main.cpp index 7d5ba21a..8cddb51e 100644 --- a/demo/magicleap/src/main.cpp +++ b/demo/magicleap/src/main.cpp @@ -126,22 +126,22 @@ graphics_context_t::~graphics_context_t() { } // Callbacks -static void onStop(void* app) +static void onStop(void* app_handle) { ML_LOG(Info, "%s: On stop called.", application_name); } -static void onPause(void* app) +static void onPause(void* app_handle) { ML_LOG(Info, "%s: On pause called.", application_name); } -static void onResume(void* app) +static void onResume(void* app_handle) { ML_LOG(Info, "%s: On resume called.", application_name); } -static void onNewInitArg(void* app) +static void onNewInitArg(void* app_handle) { ML_LOG(Info, "%s: On new init arg called.", application_name); @@ -188,6 +188,16 @@ static void onNewInitArg(void* app) } // Tell pathfinder to load the file + if (!app_handle) { + ML_LOG(Error, "%s: Init arg set before app is initialized.", application_name); + return; + } + void* app = *((void**)app_handle); + if (!app) { + ML_LOG(Error, "%s: Init arg set before app is initialized.", application_name); + return; + } + magicleap_pathfinder_demo_load(app, file_name); MLLifecycleFreeInitArgList(&arg_list); } @@ -202,6 +212,21 @@ int main() { // set up host-specific graphics surface graphics_context_t graphics_context; + // the app will go here once it's initialized + void* app = nullptr; + + // let system know our app has started + MLLifecycleCallbacks lifecycle_callbacks = {}; + lifecycle_callbacks.on_stop = onStop; + lifecycle_callbacks.on_pause = onPause; + lifecycle_callbacks.on_resume = onResume; + lifecycle_callbacks.on_new_initarg = onNewInitArg; + + if (MLResult_Ok != MLLifecycleInit(&lifecycle_callbacks, &app)) { + ML_LOG(Error, "%s: Failed to initialize lifecycle.", application_name); + return -1; + } + // Check privileges if (MLResult_Ok != MLPrivilegesStartup()) { ML_LOG(Error, "%s: Failed to initialize privileges.", application_name); @@ -229,25 +254,13 @@ int main() { // Initialize pathfinder ML_LOG(Info, "%s: Initializing demo.", application_name); - void* app = magicleap_pathfinder_demo_init(graphics_context.egl_display, graphics_context.egl_context); + app = magicleap_pathfinder_demo_init(graphics_context.egl_display, graphics_context.egl_context); if (!app) { ML_LOG(Error, "%s: Failed to initialize demo.", application_name); } - // let system know our app has started - MLLifecycleCallbacks lifecycle_callbacks = {}; - lifecycle_callbacks.on_stop = onStop; - lifecycle_callbacks.on_pause = onPause; - lifecycle_callbacks.on_resume = onResume; - lifecycle_callbacks.on_new_initarg = onNewInitArg; - - if (MLResult_Ok != MLLifecycleInit(&lifecycle_callbacks, app)) { - ML_LOG(Error, "%s: Failed to initialize lifecycle.", application_name); - return -1; - } - // Get the initial argument if there is one. - onNewInitArg(app); + onNewInitArg(&app); // Run the demo! ML_LOG(Info, "%s: Begin demo.", application_name);