@@ -126,22 +126,22 @@ graphics_context_t::~graphics_context_t() {
126
126
}
127
127
128
128
// Callbacks
129
- static void onStop (void * app )
129
+ static void onStop (void * app_handle )
130
130
{
131
131
ML_LOG (Info, " %s: On stop called." , application_name);
132
132
}
133
133
134
- static void onPause (void * app )
134
+ static void onPause (void * app_handle )
135
135
{
136
136
ML_LOG (Info, " %s: On pause called." , application_name);
137
137
}
138
138
139
- static void onResume (void * app )
139
+ static void onResume (void * app_handle )
140
140
{
141
141
ML_LOG (Info, " %s: On resume called." , application_name);
142
142
}
143
143
144
- static void onNewInitArg (void * app )
144
+ static void onNewInitArg (void * app_handle )
145
145
{
146
146
ML_LOG (Info, " %s: On new init arg called." , application_name);
147
147
@@ -188,6 +188,16 @@ static void onNewInitArg(void* app)
188
188
}
189
189
190
190
// 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
+
191
201
magicleap_pathfinder_demo_load (app, file_name);
192
202
MLLifecycleFreeInitArgList (&arg_list);
193
203
}
@@ -202,6 +212,21 @@ int main() {
202
212
// set up host-specific graphics surface
203
213
graphics_context_t graphics_context;
204
214
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
+
205
230
// Check privileges
206
231
if (MLResult_Ok != MLPrivilegesStartup ()) {
207
232
ML_LOG (Error, " %s: Failed to initialize privileges." , application_name);
@@ -228,22 +253,14 @@ int main() {
228
253
}
229
254
230
255
// 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);
243
260
}
244
261
245
262
// Get the initial argument if there is one.
246
- onNewInitArg (app);
263
+ onNewInitArg (& app);
247
264
248
265
// Run the demo!
249
266
ML_LOG (Info, " %s: Begin demo." , application_name);
0 commit comments