From 27c166b0b392fc5244cb8f155407921ed0c2fc7a Mon Sep 17 00:00:00 2001 From: Erik van Bilsen Date: Fri, 2 Sep 2022 08:56:51 -0700 Subject: Made Android native activity available before calling sokol_main (#708) --- sokol_app.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sokol_app.h b/sokol_app.h index e2cc6048..a7126dfc 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -9194,11 +9194,14 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* saved_state, size _SOKOL_UNUSED(saved_state_size); SOKOL_LOG("NativeActivity onCreate()"); + // Set activity *before* calling sokol_main. + // See https://github.com/floooh/sokol/issues/708 + _sapp.android.activity = activity; + sapp_desc desc = sokol_main(0, NULL); _sapp_init_state(&desc); /* start loop thread */ - _sapp.android.activity = activity; int pipe_fd[2]; if (pipe(pipe_fd) != 0) { @@ -12067,7 +12070,6 @@ SOKOL_API_IMPL const void* sapp_wgpu_get_depth_stencil_view(void) { } SOKOL_API_IMPL const void* sapp_android_get_native_activity(void) { - SOKOL_ASSERT(_sapp.valid); #if defined(_SAPP_ANDROID) return (void*)_sapp.android.activity; #else -- cgit v1.2.3 From 36f600a646086ff379a7e0a1ea5474e2987467f0 Mon Sep 17 00:00:00 2001 From: Andre Weissflog Date: Sat, 3 Sep 2022 14:05:48 +0200 Subject: sokol_app.h android: store native activity pointer before and after _sapp_init_state() --- sokol_app.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sokol_app.h b/sokol_app.h index a7126dfc..80c80ed8 100644 --- a/sokol_app.h +++ b/sokol_app.h @@ -9194,14 +9194,15 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* saved_state, size _SOKOL_UNUSED(saved_state_size); SOKOL_LOG("NativeActivity onCreate()"); - // Set activity *before* calling sokol_main. - // See https://github.com/floooh/sokol/issues/708 + // the NativeActity pointer needs to be available inside sokol_main() + // (see https://github.com/floooh/sokol/issues/708), however _sapp_init_state() + // will clear the global _sapp_t struct, so we need to initialize the native + // activity pointer twice, once before sokol_main() and once after _sapp_init_state() + _sapp_clear(&_sapp, sizeof(_sapp)); _sapp.android.activity = activity; - sapp_desc desc = sokol_main(0, NULL); _sapp_init_state(&desc); - - /* start loop thread */ + _sapp.android.activity = activity; int pipe_fd[2]; if (pipe(pipe_fd) != 0) { @@ -12070,6 +12071,8 @@ SOKOL_API_IMPL const void* sapp_wgpu_get_depth_stencil_view(void) { } SOKOL_API_IMPL const void* sapp_android_get_native_activity(void) { + // NOTE: _sapp.valid is not asserted here because sapp_android_get_native_activity() + // needs to be callable from within sokol_main() (see: https://github.com/floooh/sokol/issues/708) #if defined(_SAPP_ANDROID) return (void*)_sapp.android.activity; #else -- cgit v1.2.3