This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Android RunLoop implementation doesn't work for main thread #4682
Copy link
Copy link
Closed
Labels
AndroidMapbox Maps SDK for Android
Description
Being able to construct an instance of RunLoop that dispatches timers and async tasks on the main thread is a requirement for MapContext thread removal (#2909). However, the Android RunLoop implementation does not do anything special to handle Type::Default, and doesn't construct a static RunLoop for the main thread.
It's not clear to me if you can even use the native-level "Looper" on the main thread. We may have to replace this implementation with a JNI implementation using the Java class.
If you try to run #2909 on Android, you'll see the following crash:
04-11 17:59:00.138 959-959/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x1c
04-11 17:59:00.141 959-959/? A/DEBUG: eax 00000000 ebx a2bb1b80 ecx 00000001 edx b77aacc0
04-11 17:59:00.141 959-959/? A/DEBUG: esi a2bcd7e0 edi a2bcd7e0
04-11 17:59:00.141 959-959/? A/DEBUG: xcs 00000073 xds 0000007b xes 0000007b xfs 00000007 xss 0000007b
04-11 17:59:00.142 959-959/? A/DEBUG: eip a2922ba6 ebp bfd94b98 esp bfd94b80 flags 00210246
04-11 17:59:00.249 959-959/? A/DEBUG: #00 pc 0023fba6 /data/app/com.mapbox.mapboxsdk.testapp-1/lib/x86/libmapbox-gl.so (mbgl::util::RunLoop::getLoopHandle()+38)
04-11 17:59:00.249 959-959/? A/DEBUG: #01 pc 0023f02f /data/app/com.mapbox.mapboxsdk.testapp-1/lib/x86/libmapbox-gl.so (mbgl::util::AsyncTask::Impl::Impl(std::__1::function<void ()>&&)+63)
04-11 17:59:00.249 959-959/? A/DEBUG: #02 pc 0023ef44 /data/app/com.mapbox.mapboxsdk.testapp-1/lib/x86/libmapbox-gl.so (mbgl::util::AsyncTask::AsyncTask(std::__1::function<void ()>&&)+52)
04-11 17:59:00.249 959-959/? A/DEBUG: #03 pc 0018f819 /data/app/com.mapbox.mapboxsdk.testapp-1/lib/x86/libmapbox-gl.so (mbgl::MapContext::MapContext(mbgl::View&, mbgl::FileSource&, mbgl::MapMode, mbgl::GLContextMode, float)+297)
04-11 17:59:00.256 959-959/? A/DEBUG: #04 pc 0018b615 /data/app/com.mapbox.mapboxsdk.testapp-1/lib/x86/libmapbox-gl.so (mbgl::Map::Map(mbgl::View&, mbgl::FileSource&, mbgl::MapMode, mbgl::GLContextMode, mbgl::ConstrainMode)+181)
04-11 17:59:00.256 959-959/? A/DEBUG: #05 pc 000d8d70 /data/app/com.mapbox.mapboxsdk.testapp-1/lib/x86/libmapbox-gl.so (mbgl::android::NativeMapView::NativeMapView(_JNIEnv*, _jobject*, float, int, unsigned int)+576)
04-11 17:59:00.256 959-959/? A/DEBUG: #06 pc 000f5a8b /data/app/com.mapbox.mapboxsdk.testapp-1/lib/x86/libmapbox-gl.so
04-11 17:59:00.256 959-959/? A/DEBUG: #07 pc 007ec232 /data/app/com.mapbox.mapboxsdk.testapp-1/oat/x86/base.odex (offset 0x54e000) (long com.mapbox.mapboxsdk.maps.NativeMapView.nativeCreate(java.lang.String, java.lang.String, java.lang.String, float, int, long)+246)
04-11 17:59:00.256 959-959/? A/DEBUG: #08 pc 007eb5dd /data/app/com.mapbox.mapboxsdk.testapp-1/oat/x86/base.odex (offset 0x54e000) (void com.mapbox.mapboxsdk.maps.NativeMapView.<init>(com.mapbox.mapboxsdk.maps.MapView)+1137)
04-11 17:59:00.256 959-959/? A/DEBUG: #09 pc 007d2dc1 /data/app/com.mapbox.mapboxsdk.testapp-1/oat/x86/base.odex (offset 0x54e000) (void com.mapbox.mapboxsdk.maps.MapView.initialize(android.content.Context, com.mapbox.mapboxsdk.maps.MapboxMapOptions)+1013)
04-11 17:59:00.256 959-959/? A/DEBUG: #10 pc 007d0b35 /data/app/com.mapbox.mapboxsdk.testapp-1/oat/x86/base.odex (offset 0x54e000) (void com.mapbox.mapboxsdk.maps.MapView.<init>(android.content.Context, android.util.AttributeSet)+313)
04-11 17:59:00.256 959-959/? A/DEBUG: #11 pc 00137a82 /system/lib/libart.so (art_quick_invoke_stub+338)
04-11 17:59:00.256 959-959/? A/DEBUG: #12 pc 001435c4 /system/lib/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+212)
04-11 17:59:00.257 959-959/? A/DEBUG: #13 pc 0050f858 /system/lib/libart.so (art::InvokeMethod(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned int)+1736)
04-11 17:59:00.257 959-959/? A/DEBUG: #14 pc 00480f4f /system/lib/libart.so (art::Constructor_newInstance(_JNIEnv*, _jobject*, _jobjectArray*)+367)
04-11 17:59:00.257 959-959/? A/DEBUG: #15 pc 73277ab4 /data/dalvik-cache/x86/system@[email protected] (offset 0x1eb2000)
This crash indicates that the main thread does not have a RunLoop.
cc @tmpsantos
Activity
tmpsantos commentedon Apr 12, 2016
It is possible, we need to wake up the main loop of type
Defaultpinging a FD added withALooper_addFd. I working now on fixing a crash on the RunLoop and will jump on this one next.tmpsantos commentedon Apr 13, 2016
@jfirebaugh can you 👀 at https://github.com/mapbox/mapbox-gl-native/tree/tmpsantos-android_main_thread ?
These are the changes needed to get Android rendering on the main thread. You can probably just cherry-pick the
[android]patches to your branch.jfirebaugh commentedon Apr 13, 2016
Merged to #2909.
[android] Use ALooper_addFd() and callbacks to wake up
[android] Use ALooper_addFd() and callbacks to wake up