aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Weissflog <floooh@gmail.com>2022-09-03 14:06:18 +0200
committerAndre Weissflog <floooh@gmail.com>2022-09-03 14:06:18 +0200
commit04ee0fa8f338bbc01a360ebbc3a5189a1c0b4eec (patch)
treecff92b1008fcf88362642ad65a281bf539fc485c
parent01eeb35658fee9b6fe2e31145925fbd5e22faf47 (diff)
parent36f600a646086ff379a7e0a1ea5474e2987467f0 (diff)
Merge branch 'neslib-master'
(sokol_app.h android: make native activity pointer available in sokol_main)
-rw-r--r--sokol_app.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/sokol_app.h b/sokol_app.h
index e2cc6048..80c80ed8 100644
--- a/sokol_app.h
+++ b/sokol_app.h
@@ -9194,10 +9194,14 @@ void ANativeActivity_onCreate(ANativeActivity* activity, void* saved_state, size
_SOKOL_UNUSED(saved_state_size);
SOKOL_LOG("NativeActivity onCreate()");
+ // 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];
@@ -12067,7 +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) {
- SOKOL_ASSERT(_sapp.valid);
+ // 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