Skip to content

Commit fd3d75d

Browse files
author
Alan Jeffrey
committed
Fix the magicleap app to work in LuminOS 0.96
1 parent 7cd05cd commit fd3d75d

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

demo/magicleap/src/main.cpp

+34-17
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,22 @@ graphics_context_t::~graphics_context_t() {
126126
}
127127

128128
// Callbacks
129-
static void onStop(void* app)
129+
static void onStop(void* app_handle)
130130
{
131131
ML_LOG(Info, "%s: On stop called.", application_name);
132132
}
133133

134-
static void onPause(void* app)
134+
static void onPause(void* app_handle)
135135
{
136136
ML_LOG(Info, "%s: On pause called.", application_name);
137137
}
138138

139-
static void onResume(void* app)
139+
static void onResume(void* app_handle)
140140
{
141141
ML_LOG(Info, "%s: On resume called.", application_name);
142142
}
143143

144-
static void onNewInitArg(void* app)
144+
static void onNewInitArg(void* app_handle)
145145
{
146146
ML_LOG(Info, "%s: On new init arg called.", application_name);
147147

@@ -188,6 +188,16 @@ static void onNewInitArg(void* app)
188188
}
189189

190190
// Tell pathfinder to load the file
191+
if (!app_handle) {
192+
ML_LOG(Error, "%s: Init arg set before app is initialized.", application_name);
193+
return;
194+
}
195+
void* app = *((void**)app_handle);
196+
if (!app) {
197+
ML_LOG(Error, "%s: Init arg set before app is initialized.", application_name);
198+
return;
199+
}
200+
191201
magicleap_pathfinder_demo_load(app, file_name);
192202
MLLifecycleFreeInitArgList(&arg_list);
193203
}
@@ -202,6 +212,21 @@ int main() {
202212
// set up host-specific graphics surface
203213
graphics_context_t graphics_context;
204214

215+
// the app will go here once it's initialized
216+
void* app = nullptr;
217+
218+
// let system know our app has started
219+
MLLifecycleCallbacks lifecycle_callbacks = {};
220+
lifecycle_callbacks.on_stop = onStop;
221+
lifecycle_callbacks.on_pause = onPause;
222+
lifecycle_callbacks.on_resume = onResume;
223+
lifecycle_callbacks.on_new_initarg = onNewInitArg;
224+
225+
if (MLResult_Ok != MLLifecycleInit(&lifecycle_callbacks, &app)) {
226+
ML_LOG(Error, "%s: Failed to initialize lifecycle.", application_name);
227+
return -1;
228+
}
229+
205230
// Check privileges
206231
if (MLResult_Ok != MLPrivilegesStartup()) {
207232
ML_LOG(Error, "%s: Failed to initialize privileges.", application_name);
@@ -228,22 +253,14 @@ int main() {
228253
}
229254

230255
// Initialize pathfinder
231-
void* app = magicleap_pathfinder_demo_init(graphics_context.egl_display, graphics_context.egl_context);
232-
233-
// let system know our app has started
234-
MLLifecycleCallbacks lifecycle_callbacks = {};
235-
lifecycle_callbacks.on_stop = onStop;
236-
lifecycle_callbacks.on_pause = onPause;
237-
lifecycle_callbacks.on_resume = onResume;
238-
lifecycle_callbacks.on_new_initarg = onNewInitArg;
239-
240-
if (MLResult_Ok != MLLifecycleInit(&lifecycle_callbacks, app)) {
241-
ML_LOG(Error, "%s: Failed to initialize lifecycle.", application_name);
242-
return -1;
256+
ML_LOG(Info, "%s: Initializing demo.", application_name);
257+
app = magicleap_pathfinder_demo_init(graphics_context.egl_display, graphics_context.egl_context);
258+
if (!app) {
259+
ML_LOG(Error, "%s: Failed to initialize demo.", application_name);
243260
}
244261

245262
// Get the initial argument if there is one.
246-
onNewInitArg(app);
263+
onNewInitArg(&app);
247264

248265
// Run the demo!
249266
ML_LOG(Info, "%s: Begin demo.", application_name);

0 commit comments

Comments
 (0)