Forum Libraries, Components, and Plugins

Mapbox SDK component crashes on launch with EGL_BAD_DISPLAY

I'm trying to use the Mapbox SDK component in a Xamarin.Forms app. I've created a custom renderer which creates the native MapView, but when the app comes up it immediately crashes with this error:

[libEGL] validate_display:254 error 3008 (EGL_BAD_DISPLAY)
[mbgl] {Main}[OpenGL]: eglCreateWindowSurface() returned error 12296
[libc] Fatal signal 6 (SIGABRT) at 0x00000941 (code=-6), thread 2369

This occurs on three different devices:
1. Kindle Fire HD running Fire OS 4.5.5, based on Android 4.4.3 (API 19) which supports OpenGL ES 2.0 at least, and possibly OpenGL ES 3.0 depending on GPU support (not sure).
2. Visual Studio Emulator for Android running Android 4.4 (API 19, similar to Asus Google Nexus 7), which supports OpenGL ES 2.0, and most of OpenGL ES 3.0.
3. Visual Studio Emulator for Android running Android 5.1.1 (API 22, similar to Asus Google Nexus 7), which also supports OpenGL ES 2.0 and most of OpenGL ES 3.0.

I'm following James Montemagno's blog post on creating custom Xamarin.Forms controls on Android. All I've done is add an instance of the control to my main page, and initialize it like this in the custom renderer:

[assembly: ExportRenderer (typeof (MapboxView), typeof (MapboxRenderer))]

    public class MapboxRenderer : ViewRenderer<MapboxView, MapView>
    {
        public MapboxRenderer()
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<MapboxView> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement == null && this.Element != null)
            {
                var appKey = "MY_ACCESS_TOKEN";
                var m = new MapView(Forms.Context, appKey, Mapbox.Constants.Style.Emerald)
                    {
                        CenterCoordinate = new LatLng(45, -120),
                        ZoomLevel = 11,
                        LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                    };

                SetNativeControl(m);
            }
        }
    }

I also added the following to my AndroidManifest.xml file, so the app should complain on launch if OpenGL ES 2.0 is not available:

<uses-feature android:glEsVersion="0x00020000" android:required="true" />

The Mapbox SDK component states it only uses OpenGL ES 2.0, so it seems pretty clear that this should work on all three devices.

Unfortunately, it doesn't, and they're all crashing with the same error. Any ideas why I'm getting this?

Thanks in advance for any help!

Answers

  • BobMeyersBobMeyers USMember ✭✭

    UPDATE: This is apparently a Mapbox issue, currently unassigned.

  • BobMeyersBobMeyers USMember ✭✭

    The Mapbox issue referenced above is still open, but the problem I was seeing was actually due to incomplete initialization. Specifically, I was missing a call to MapView.OnCreate().

    The Mapbox SDK sample code shows this being done inside the main Activity's OnCreate method for Android. However, this is not easy when using Xamarin Forms like in my case, because the native control doesn't get created until later when the view's custom renderer gets initialized.

    I fixed this by calling MapView.OnCreate(null) in the custom renderer's OnElementChanged method when the native MapView is actually created. This won't be a complete solution though if it turns out I need to pass in the Bundle provided to the Activity's OnCreate method, which unfortunately isn't available at the point where the MapView is being initialized.

Sign In or Register to comment.