From 97a39d7947d4fdc8532a64d57a241beb4bfc9b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 15 Mar 2018 10:54:15 +0100 Subject: [PATCH] Platform: the Android app_dummy() workaround only got worse. What to expect with Android, eh?! --- src/Magnum/Platform/AndroidApplication.cpp | 23 ++++++++++++++++------ src/Magnum/Platform/CMakeLists.txt | 4 ---- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Magnum/Platform/AndroidApplication.cpp b/src/Magnum/Platform/AndroidApplication.cpp index f0303666a..4619696dc 100644 --- a/src/Magnum/Platform/AndroidApplication.cpp +++ b/src/Magnum/Platform/AndroidApplication.cpp @@ -34,6 +34,10 @@ #include "Implementation/Egl.h" +/* This function would be stripped by the linker otherwise. Search for the name + below for the complete rant. */ +extern "C" void ANativeActivity_onCreate(struct ANativeActivity*, void*, size_t); + namespace Magnum { namespace Platform { struct AndroidApplication::LogOutput { @@ -155,10 +159,12 @@ void AndroidApplication::mouseMoveEvent(MouseMoveEvent&) {} namespace { struct Data { - Data(std::unique_ptr(*instancer)(const AndroidApplication::Arguments&)): instancer(instancer) {} + Data(std::unique_ptr(*instancer)(const AndroidApplication::Arguments&), void(*nativeActivity)(ANativeActivity*,void*,size_t)): instancer(instancer), nativeActivity{nativeActivity} {} std::unique_ptr(*instancer)(const AndroidApplication::Arguments&); std::unique_ptr instance; + + void(*nativeActivity)(ANativeActivity*,void*,size_t); }; } @@ -220,12 +226,17 @@ void AndroidApplication::exec(android_app* state, std::unique_ptronAppCmd = commandEvent; state->onInputEvent = inputEvent; - /* Make sure the glue isn't stripped. WHY WHYYY CAN'T THIS BE DONE SOME - SANE WAY WHYY */ - app_dummy(); - + /* Long time ago there was a call to app_dummy() that prevented stripping + the ANativeActivity_onCreate() symbol. It was awful enough on its own, + but they decided that it's no longer needed and the PROPER AND BETTER + SOLUTION is to pollute all downstream build scripts with + `-u ANativeActivity_onCreate` passed to linker. That's just fucking + awful. I can't use app_dummy() as it's deprecated, so I'm simply + retrieving the function pointer to the ANativeActivity_onCreate function + and saving it somewhere to convince the linker it's really needed. I + WANT TO SCREAM. https://github.com/android-ndk/ndk/issues/381 */ /** @todo Make use of saved state */ - Data data{instancer}; + Data data{instancer, ANativeActivity_onCreate}; state->userData = &data; for(;;) { diff --git a/src/Magnum/Platform/CMakeLists.txt b/src/Magnum/Platform/CMakeLists.txt index f7eab5290..9b9e7b8b7 100644 --- a/src/Magnum/Platform/CMakeLists.txt +++ b/src/Magnum/Platform/CMakeLists.txt @@ -75,10 +75,6 @@ if(WITH_ANDROIDAPPLICATION) set_target_properties(MagnumAndroidApplicationGlue PROPERTIES CORRADE_USE_PEDANTIC_FLAGS OFF FOLDER "Magnum/Platform") - # They just don't care, so of course the ANativeActivity_onCreate() - # function is not exported and thus the app startup fails if I don't - # disable hidden visibility for the file. - target_compile_options(MagnumAndroidApplicationGlue PRIVATE "-fvisibility=default") add_library(MagnumAndroidApplication STATIC ${MagnumAndroidApplication_SRCS}