Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
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

Closed

Description

@jfirebaugh

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

  1. added
    Android
    on Apr 12, 2016
  2. self-assigned this
    on Apr 12, 2016
  3. tmpsantos commented on Apr 12, 2016

    @tmpsantos
    Contributor

    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.

    It is possible, we need to wake up the main loop of type Default pinging a FD added with ALooper_addFd. I working now on fixing a crash on the RunLoop and will jump on this one next.

  4. tmpsantos commented on Apr 13, 2016

    @tmpsantos
    Contributor

    @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.

  5. jfirebaugh commented on Apr 13, 2016

    @jfirebaugh
    ContributorAuthor

    Merged to #2909.

  6. added 2 commits that reference this issue on Apr 14, 2016
    056f61f
    40e590b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Android

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions