mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

Android crashes on startup

Open iCyberon opened this issue 11 years ago • 54 comments

Hey guys,

Looks like mapbox crashes for some devices on start.

14620-14620/am.ggtaxi.main.ggdriver E/libEGL: validate_display:254 error 3008 (EGL_BAD_DISPLAY)
14620-14620/am.ggtaxi.main.ggdriver E/mbgl: {Main}[OpenGL]: eglCreateWindowSurface() returned error 12296
14620-14620/am.ggtaxi.main.ggdriver A/libc: Fatal signal 6 (SIGABRT) at 0x0000391c (code=-6), thread 14620 (i.main.ggdriver)

Device: Samsung Galaxy Tab Pro 8.4 3G/LTE Android Version: 4.2.2

iCyberon avatar Nov 10 '15 15:11 iCyberon

Some more info:

11-10 19:21:00.328 25781-25781/am.ggtaxi.main.ggdriver I/mbgl: {Main}[OpenGL]: GL Vendor: Vivante Corporation
11-10 19:21:00.328 25781-25781/am.ggtaxi.main.ggdriver I/mbgl: {Main}[OpenGL]: GL Renderer: Vivante GC1000
11-10 19:21:00.328 25781-25781/am.ggtaxi.main.ggdriver I/mbgl: {Main}[OpenGL]: GL Version: OpenGL ES 2.0
11-10 19:21:00.328 25781-25781/am.ggtaxi.main.ggdriver I/mbgl: {Main}[OpenGL]: GL SL Version: OpenGL ES GLSL ES 1.00
11-10 19:21:00.328 25781-25781/am.ggtaxi.main.ggdriver I/mbgl: {Main}[OpenGL]: GL Extensions: GL_EXT_debug_marker GL_OES_compressed_ETC1_RGB8_texture GL_OES_compressed_paletted_texture GL_OES_EGL_image GL_OES_depth24 GL_OES_fbo_render_mipmap GL_OES_fragment_precision_high GL_OES_rgb8_rgba8 GL_OES_stencil1 GL_OES_stencil4 GL_OES_texture_npot GL_OES_vertex_half_float GL_OES_depth_texture GL_OES_packed_depth_stencil GL_OES_standard_derivatives GL_OES_get_program_binary GL_EXT_texture_format_BGRA8888 GL_IMG_read_format GL_EXT_blend_minmax GL_EXT_read_format_bgra GL_EXT_multi_draw_arrays GL_APPLE_texture
11-10 19:21:00.328 25781-25781/am.ggtaxi.main.ggdriver I/mbgl: {Main}[OpenGL]: GL Extensions: _format_BGRA8888 GL_APPLE_texture_max_level GL_ARM_rgba8 GL_EXT_frag_depth GL_VIV_shader_binary GL_VIV_direct_texture GL_OES_EGL_image_external GL_EXT_discard_framebuffer GL_EXT_multisampled_render_to_texture GL_VIV_clamp_to_border GL_MRVL_texture_video GL_EXT_unpack_subimage GL_OES_element_index_uint GL_OES_mapbuffer GL_EXT_texture_compression_dxt1 GL_EXT_texture_compression_s3tc
11-10 19:21:01.329 25781-26261/am.ggtaxi.main.ggdriver E/libEGL: eglMakeCurrent:779 error 3002 (EGL_BAD_ACCESS)
11-10 19:21:01.329 25781-26261/am.ggtaxi.main.ggdriver E/mbgl: {Map}[OpenGL]: eglMakeCurrent() returned error 12290
11-10 19:21:01.329 25781-26261/am.ggtaxi.main.ggdriver A/libc: Fatal signal 6 (SIGABRT) at 0x000064b5 (code=-6), thread 26261 (i.main.ggdriver)

iCyberon avatar Nov 10 '15 15:11 iCyberon

@iCyberon Can you see if you can find the native stack trace.

In logcat change the "Show only selected application" to "No filter"

In the search box put "DEBUG" You should see a bunch of lines where the first line is a series of -------

ljbade avatar Nov 11 '15 10:11 ljbade

The same on Samsung Galaxy Tab 3 7.0, Android 4.2.2. This seems to be the origin of the error https://github.com/mapbox/mapbox-gl-native/blob/43dde0f204ac770feae0ef22c7a4ea67585deb12/platform/android/native_map_view.cpp#L140

vkurchatkin avatar Nov 18 '15 10:11 vkurchatkin

I'm getting the same error 3008 (EGL_BAD_DISPLAY) in eglCreateWindowSurface when creating a MapView on these devices:

  • Kindle Fire HD 3rd Gen running Fire OS 4.5.5 (based on Android 4.4)
  • Visual Studio Android Emulator 7" XHDPI Tablet running Android 4.4 (similar to Asus Google Nexus 7)
  • Visual Studio Android Emulator 7" XHDPI Tablet running Android 5.1.1 (similar to Asus Google Nexus 7)

Totally blocked right now... :(

bobmeyers5 avatar Nov 18 '15 16:11 bobmeyers5

I think this only happens on tablets.

iCyberon avatar Nov 18 '15 16:11 iCyberon

Attaching some relevant debug log info from the Kindle Fire HD after enabling OpenGL traces (logcat) in Developer Options.

From Xamarin Studio debugger's Application Output window: mapbox-opengl-error-log.txt

Logcat details from DDMS: mapbox-opengl-error-stack-trace.txt

bobmeyers5 avatar Nov 18 '15 16:11 bobmeyers5

@iCyberon, possible -- all my previous tests above were tablets. However, I just tried it on VS Android Emulator 5.5" XXHPDI Phone running Android 5.1.1 (similar to LG G4) and got the same error.

bobmeyers5 avatar Nov 18 '15 17:11 bobmeyers5

@bmeyers43 It's related to DPI I guess. http://forum.xda-developers.com/showthread.php?t=2212632

iCyberon avatar Nov 18 '15 18:11 iCyberon

Maybe...that bug was happening in eglSwapBuffers, but we're seeing it in eglCreateWindowSurface. Also, the Fire HD reports 216 dpi, while the VS Emulator images both claim to be 323 dpi, so I'm not sure what values/ranges would lead to this error.

bobmeyers5 avatar Nov 18 '15 21:11 bobmeyers5

on x86 architecture using Genymotion and latest SNAPSHOT, I was able to:

  • run it on + 5.0.0 devices
  • crash on pre 5.0.0 devices

Note: I was able to run on 4.2.2 wiht ARM without a problem

tobrun avatar Nov 19 '15 10:11 tobrun

~~I am getting the same crash on a Sony Z2(5.1.1) and a Nexus 4(5.1.1).~~

Never mind, by bad :-)

esisa avatar Nov 19 '15 21:11 esisa

@tobrun, since you are able to repro on at least some devices now, when do you think this will get assigned/fixed?

bobmeyers5 avatar Nov 21 '15 17:11 bobmeyers5

Looking into this: Will use android 4.2.2 on x86 (nexus 7 genymotion):

Used following build command:

BUILDTYPE=Debug make android-lib-x86

I'm getting following recurring stacktraces:

http://pastebin.com/6eLwYTHX

Result after symbolicating:

http://pastebin.com/4fqVTXUG

The reference of NativeMapView InitializeDisplay in JNI refers to this

void JNICALL nativeInitializeDisplay(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
    mbgl::Log::Debug(mbgl::Event::JNI, "nativeInitializeDisplay");
    assert(nativeMapViewPtr != 0);
    NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);

    try
    {
        nativeMapView->initializeDisplay();
    } catch(const std::exception& e) {
        throw_jni_error(env, "Unable to initialize GL display.");
    }
}

That will call the underlying code in native_map_view.cpp:

void NativeMapView::initializeDisplay() {
    mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::initializeDisplay");

    assert(display == EGL_NO_DISPLAY);
    assert(config == nullptr);
    assert(format < 0);

    display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    if (display == EGL_NO_DISPLAY) {
        mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetDisplay() returned error %d", eglGetError());
        throw new std::runtime_error("eglGetDisplay() failed");
    }

    EGLint major, minor;
    if (!eglInitialize(display, &major, &minor)) {
        mbgl::Log::Error(mbgl::Event::OpenGL, "eglInitialize() returned error %d", eglGetError());
        throw new std::runtime_error("eglInitialize() failed");
    }
    if ((major <= 1) && (minor < 3)) {
        mbgl::Log::Error(mbgl::Event::OpenGL, "EGL version is too low, need 1.3, got %d.%d", major,
                         minor);
        throw new std::runtime_error("EGL version is too low");
    }

    log_egl_string(display, EGL_VENDOR, "Vendor");
    log_egl_string(display, EGL_VERSION, "Version");
    log_egl_string(display, EGL_CLIENT_APIS, "Client APIs");
    log_egl_string(display, EGL_EXTENSIONS, "Client Extensions");

    // Detect if we are in emulator
    if (inEmulator()) {
        mbgl::Log::Warning(mbgl::Event::Android, "In emulator! Enabling hacks :-(");
    }

    // Get all configs at least RGB 565 with 16 depth and 8 stencil
    EGLint configAttribs[] = {
        EGL_CONFIG_CAVEAT,                               EGL_NONE,           EGL_RENDERABLE_TYPE,
        EGL_OPENGL_ES2_BIT,                              EGL_SURFACE_TYPE,   EGL_WINDOW_BIT,
        EGL_BUFFER_SIZE,                                 16,                 EGL_RED_SIZE,
        5,                                               EGL_GREEN_SIZE,     6,
        EGL_BLUE_SIZE,                                   5,                  EGL_DEPTH_SIZE,
        16,                                              EGL_STENCIL_SIZE,   8,
        (inEmulator() ? EGL_NONE : EGL_CONFORMANT),        EGL_OPENGL_ES2_BIT, // Ugly hack
        (inEmulator() ? EGL_NONE : EGL_COLOR_BUFFER_TYPE), EGL_RGB_BUFFER,     // Ugly hack
        EGL_NONE};
    EGLint numConfigs;
    if (!eglChooseConfig(display, configAttribs, nullptr, 0, &numConfigs)) {
        mbgl::Log::Error(mbgl::Event::OpenGL, "eglChooseConfig(NULL) returned error %d",
                         eglGetError());
        throw new std::runtime_error("eglChooseConfig() failed");
    }
    if (numConfigs < 1) {
        mbgl::Log::Error(mbgl::Event::OpenGL, "eglChooseConfig() returned no configs.");
        throw new std::runtime_error("eglChooseConfig() failed");
    }

    const auto configs = std::make_unique<EGLConfig[]>(numConfigs);
    if (!eglChooseConfig(display, configAttribs, configs.get(), numConfigs, &numConfigs)) {
        mbgl::Log::Error(mbgl::Event::OpenGL, "eglChooseConfig() returned error %d", eglGetError());
        throw new std::runtime_error("eglChooseConfig() failed");
    }

    config = chooseConfig(configs.get(), numConfigs);
    if (config == nullptr) {
        mbgl::Log::Error(mbgl::Event::OpenGL, "No config chosen");
        throw new std::runtime_error("No config chosen");
    }

    if (!eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format)) {
        mbgl::Log::Error(mbgl::Event::OpenGL, "eglGetConfigAttrib() returned error %d",
                         eglGetError());
        throw new std::runtime_error("eglGetConfigAttrib() failed");
    }
    mbgl::Log::Info(mbgl::Event::OpenGL, "Chosen window format is %d", format);
}

tobrun avatar Nov 22 '15 19:11 tobrun

A difference I'm noticing between the working genymotion images versus non-working are the GL version:

Not working logs:

OpenGL ES-CM 1.1 (2.1 INTEL-10.10.18)

Working logs:

OpenGL ES 2.0 (2.1 INTEL-10.10.18)

Also I found this #573 from @ljbade, it indicates problems related to getting OpenGL ES 2.0 working on emulators.

tobrun avatar Nov 22 '15 19:11 tobrun

I'm putting above as a works as designed, the SDK requires a minimum version of OpenGL ES 2.0, we can't enforce this ourselves while running from the IDE but Google Play will filter out devices not having this requirement. The reason why that virtual machine is not able to use the host machine GPU is very strange to me. Need to reach out to Genymotion to get more information.

tobrun avatar Nov 23 '15 09:11 tobrun

After investigating my startup crash I'm back at square one. I will try to approach each mentioned problem above individually:

@iCyberon, @vkurchatkin: Could you add the stack trace @ljbade requested? Without that trace it will be difficult to investigate the issue.

@bmeyers43: I stumbled on your thread on the Xamarin forums. Since this is not working on any devices for you, I believe something else is going wrong. Is it possible that you are not hooking into the required lifecycle methods as shown here?

Thank you in advance,

tobrun avatar Nov 23 '15 10:11 tobrun

Here it goes: https://gist.github.com/vkurchatkin/1652ed747de48721ae80

vkurchatkin avatar Nov 23 '15 11:11 vkurchatkin

@vkurchatkin

Thank you, this is the result after symbolicating the crash:

********** Crash dump: ********** Build fingerprint: 'samsung/goya3gxx/goya3g:4.2.2/JDQ39/T111XXUAOE1:user/release-keys' pid: 5147, tid: 5186, name: Map >>> com.mapbox.mapboxgl.testapp <<< signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr deadbaad Stack frame #00 pc 0001ad02 /system/lib/libc.so Stack frame #01 pc 000180a0 /system/lib/libc.so (abort+4) Stack frame #02 pc 003e0440 /data/app-lib/com.mapbox.mapboxgl.testapp-7/libmapbox-gl.so Stack frame #03 pc 003e05b4 /data/app-lib/com.mapbox.mapboxgl.testapp-7/libmapbox-gl.so Stack frame #04 pc 003d0bc8 /data/app-lib/com.mapbox.mapboxgl.testapp-7/libmapbox-gl.so

fault addr deadbaad on libc.so indicates that there is a problem with a corrupt memory heap.

/cc @zugaldia

tobrun avatar Nov 23 '15 13:11 tobrun

@tobrun but doesn't it happen AFTER eglMakeCurrent returns an error? this seems to be the root of the problem

vkurchatkin avatar Nov 23 '15 13:11 vkurchatkin

@vkurchatkin I believe you are right,

eglMakeCurrent is currently returning EGL_BAD_ACCESS

From Romain Guy: Two possible reasons for this failure:

  • If ctx is current to some other thread, or if either draw or read are bound to contexts in another thread, an EGL_BAD_ACCESS error is generated.
  • If binding ctx would exceed the number of current contexts of that client API type supported by the implementation, an EGL_BAD_ACCESS error is generated.

It could also be that the GPU you are using on tablets does not support shared context.

tobrun avatar Nov 23 '15 14:11 tobrun