Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Crash onPreDraw: EGL_BAD_DISPLAY #7738

Closed
grote opened this issue Jan 16, 2017 · 14 comments
Closed

Crash onPreDraw: EGL_BAD_DISPLAY #7738

grote opened this issue Jan 16, 2017 · 14 comments

Comments

@grote
Copy link

grote commented Jan 16, 2017

This issue looks very similar to #4385 and #2995, but it still happens with com.mapbox.mapboxsdk:mapbox-android-sdk:4.2.1 on Android 5.

So essentially the app crashes when trying to draw the map. Here's the stacktrace:

01-16 12:37:59.540 I/SurfaceView: updateWindow -- setFrame, this = android.view.SurfaceView{3f38acfd V.E..... ......ID 0,0-480,762 #7f0f012f app:id/surfaceView}
01-16 12:37:59.541 I/SurfaceView: updateWindow -- OnPreDrawListener, mHaveFrame = true, this = android.view.SurfaceView{3f38acfd V.E..... ......ID 0,0-480,762 #7f0f012f app:id/surfaceView}
01-16 12:37:59.542 I/SurfaceView: Changes: creating=true format=true size=true visible=true left=true top=true mUpdateWindowNeeded=false mReportDrawNeeded=false redrawNeeded=false forceSizeChanged=true mVisible=false mRequestedVisible=true, this = android.view.SurfaceView{3f38acfd V.E..... ......ID 0,0-480,762 #7f0f012f app:id/surfaceView}
01-16 12:37:59.543 D/MALI: shim_eglInitialize:715: [MALI] eglInitialize with display 0x1
01-16 12:37:59.568 I/SurfaceView: Cur surface: Surface(name=null)/@0x34932f4c, this = android.view.SurfaceView{3f38acfd V.E..... ......ID 0,0-480,762 #7f0f012f app:id/surfaceView}
01-16 12:37:59.587 I/SurfaceView: New surface: Surface(name=null)/@0x1bdc7b95, vis=true, frame=Rect(0, 38 - 480, 800), this = android.view.SurfaceView{3f38acfd V.E..... ......ID 0,0-480,762 #7f0f012f app:id/surfaceView}
01-16 12:37:59.587 I/SurfaceView: Callback --> surfaceCreated, this = android.view.SurfaceView{3f38acfd V.E..... ......ID 0,0-480,762 #7f0f012f app:id/surfaceView}
01-16 12:37:59.588 I/SurfaceView: surfaceCreated callback +, this = android.view.SurfaceView{3f38acfd V.E..... ......ID 0,0-480,762 #7f0f012f app:id/surfaceView}
01-16 12:37:59.589 D/mbgl: {liberario.debug}[JNI]: nativeCreateSurface
01-16 12:37:59.589 D/mbgl: {liberario.debug}[Android]: NativeMapView::createSurface
01-16 12:37:59.590 E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
01-16 12:37:59.590 E/mbgl: {liberario.debug}[OpenGL]: eglCreateWindowSurface() returned error 12296
01-16 12:37:59.603 I/SurfaceView: finishedDrawing, this = android.view.SurfaceView{3f38acfd V.E..... ......ID 0,0-480,762 #7f0f012f app:id/surfaceView}
01-16 12:37:59.612 D/AndroidRuntime: Shutting down VM
01-16 12:37:59.617 E/AndroidRuntime: FATAL EXCEPTION: main
                                     Process: de.grobox.liberario.debug, PID: 20514
                                     java.lang.Error: eglCreateWindowSurface() failed
                                         at com.mapbox.mapboxsdk.maps.NativeMapView.nativeCreateSurface(Native Method)
                                         at com.mapbox.mapboxsdk.maps.NativeMapView.createSurface(NativeMapView.java:131)
                                         at com.mapbox.mapboxsdk.maps.MapView$SurfaceCallback.surfaceCreated(MapView.java:1519)
                                         at android.view.SurfaceView.updateWindow(SurfaceView.java:675)
                                         at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:202)
                                         at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:944)
                                         at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2348)
                                         at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1292)
                                         at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6598)
                                         at android.view.Choreographer$CallbackRecord.run(Choreographer.java:800)
                                         at android.view.Choreographer.doCallbacks(Choreographer.java:603)
                                         at android.view.Choreographer.doFrame(Choreographer.java:572)
                                         at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:786)
                                         at android.os.Handler.handleCallback(Handler.java:815)
                                         at android.os.Handler.dispatchMessage(Handler.java:104)
                                         at android.os.Looper.loop(Looper.java:194)
                                         at android.app.ActivityThread.main(ActivityThread.java:5631)
                                         at java.lang.reflect.Method.invoke(Native Method)
                                         at java.lang.reflect.Method.invoke(Method.java:372)
                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
01-16 12:37:59.666 E/GED: Failed to get GED Log Buf, err(0)
01-16 12:37:59.667 I/OpenGLRenderer: Initialized EGL, version 1.4
01-16 12:37:59.669 D/MALI: shim_eglCreateContext:506: [MALI] eglCreateContext with display 0x1, context 0x40000001
01-16 12:37:59.669 D/MALI: _egl_make_current:857: [MALI] make current with display 0x1, context 0x40000001, state 0xb7e7a5f8
01-16 12:37:59.669 D/MALI: _egl_make_current:872: [MALI] Map __dpy 0x1 to dpy 0xb7dacce0
01-16 12:37:59.669 D/MALI: _egl_make_current:906: [MALI] Map __ctx 0x40000001 to ctx 0xb7e836d0
01-16 12:37:59.670 I/OpenGLRenderer: Get enable program binary service property (1)
01-16 12:37:59.670 I/OpenGLRenderer: Initializing program atlas...
01-16 12:37:59.671 D/ProgramBinary/Service: BpProgramBinaryService.getFileDescriptor
01-16 12:37:59.672 D/ProgramBinary/Service: BpProgramBinaryService.getProgramMapLen
01-16 12:37:59.672 D/ProgramBinary/Service: BpProgramBinaryService.getProgramMapArray
01-16 12:37:59.672 D/ProgramBinary/Service: BpProgramBinaryService.getProgramBinaryLen
01-16 12:37:59.672 I/OpenGLRenderer: Program binary detail: Binary length is 90540, program map length is 112.
01-16 12:37:59.673 I/OpenGLRenderer: Succeeded to mmap program binaries. File descriptor is 62, and path is /dev/ashmem� ~��l�
                                     �ԭ�qE���
                                     ��)�p.
01-16 12:37:59.673 I/OpenGLRenderer: No need to use file discriptor anymore, close fd(62).
01-16 12:37:59.673 D/OpenGLRenderer: TaskManager() 0xb7e91bb0, cpu = 4, thread = 2
01-16 12:37:59.673 D/OpenGLRenderer: Enabling debug mode 0
01-16 12:37:59.673 D/Surface: Surface::connect(this=0xb7e77fc8,api=1)

This is how the layout is defined:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/map"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:style_url="@string/style_mapbox_streets"/>

</android.support.constraint.ConstraintLayout>

And this is how the activity looks like:

public class NewMapActivity extends AppCompatActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_new_map);
	}

}

Please let me know if you need additional information.

@grote
Copy link
Author

grote commented Jan 16, 2017

Sorry for the noise. The error message was misleading.

In case others have a similar issue, change your activity like this:

public class NewMapActivity extends AppCompatActivity {

	MapView mapView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_new_map);

		mapView = (MapView) findViewById(R.id.map);
		mapView.onCreate(savedInstanceState);

		MapboxAccountManager.start(this, "your-api-key");
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		mapView.onSaveInstanceState(outState);
	}

	@Override
	public void onResume() {
		super.onResume();
		mapView.onResume();
	}

	@Override
	public void onPause() {
		super.onPause();
		mapView.onPause();
	}

	@Override
	public void onLowMemory() {
		super.onLowMemory();
		mapView.onLowMemory();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		mapView.onDestroy();
	}

}

@grote grote closed this as completed Jan 16, 2017
@rsahlin
Copy link

rsahlin commented Jan 26, 2017

Hi @grote I'd like to re-open this issue.

I have the same problem after rewriting MapBox support for Mapillary.

My investigation leads me to believe that the problem is with the async use of SurfaceHolder.Callback

  • The MapView.initialize() method, which is called when a mapbox component is inflated from XML, adds a SurfaceHolder callback.
  • SurfaceCallback.surfaceCreated() calls nativeMapView.createSurface to create the EGL surface.
  • The MapView.onCreate() method calls:
    nativeMapView.initializeDisplay();
    nativeMapView.initializeContext();
    and these methods must be called before the EGL surface is created (which happens in the async surfaceholder callback)

Consider what will happen if there is a delay before implementations call mapView.onCreate(bundle) from the Activity.
In that case the SurfaceHolder.surfaceCreated callback may happen before MapView.onCreate() has been called (and hence the nativeMapView has not been initialized)

I think two possible solutions to this problem could be:
A: Move the code in MapView.initialize() that adds SurfaceHolder.Callback to the SurfaceView to the onCreate() method.
B: Move the nativeMapView.initialize methods from SurfaceCallback method to the initialize() method.

Best regards
/Richard

@grote grote reopened this Jan 26, 2017
@rsahlin
Copy link

rsahlin commented Jan 26, 2017

While the above problem can be worked around by making sure that MapView.onCreate() is called directly after Activity.setContentView() there is another identical crash when I use the MapView within a custom ViewGroup (layout) with TextureView components.

In the camera activity I display the camera preview, using custom layout, on an implementation of TextureView.
When the user presses the icon to toggle map/camera the MapView object is made visible, triggering the EGL_BAD_DISPLAY exception.
Visivility of the MapView is set to GONE when entering the camera.

Could it perhaps be a similar problem with nativeMapView but related to resizing of the underlying surface?

@peterneubauer
Copy link

@zugaldia has access to the Mapillary android source and could maybe help us track this down? It's a blocker for us right now.

@zugaldia
Copy link
Member

@rsahlin Are you observing the issue in any specific devices or OS versions?

@peterneubauer I'll follow up too on the Mapillary repo.

@rsahlin
Copy link

rsahlin commented Jan 27, 2017

Hi @zugaldia

This is on the 4.2.1 branch, tested on Android 6.01

I've tried to build, in order to try to fix the problem, but I am lacking an .aar with all mapbox classes kept.
If you can provide this I can try to help pinpoint the bug next week.

If you have access to the Mapillary repo, please clone the bugfix/nestedcameralayout branch.
That will produce the crash.

Best regards
/Richard

@rsahlin
Copy link

rsahlin commented Jan 27, 2017

There is a build error that was introduced when trying to build towards your master branch.
I have fixed that in this commit:
commit c9ae546190108f72a27618f6fd6ea42c979728c6
Author: Richard Sahlin richard_sahlin@yahoo.com
Date: Fri Jan 27 15:46:30 2017 +0100

Fixup, remove Mapbox class dependency

Please make sure this is present.

@zugaldia
Copy link
Member

@rsahlin I see that you're managing instantiation and lifecycle for NativeMapView directly in MapillaryMapView. Could you provide a bit of background on why are you doing this? Is it only a temporary workaround that you used to find the information on #7738 (comment), or are you trying to do something in the app that our current API doesn't support?

@rsahlin
Copy link

rsahlin commented Jan 27, 2017

@zugaldia That class should not be there, could you please make sure you are looking at the latest commit?

  • That was just me experimenting with trying to be able to build against your .aar lib and try to fix the bug on my end.

If you look in CameraActivity I handle the lifecycle of MapView according to documentation and camera.xml is used as content view (it uses com.mapbox.mapboxsdk.maps.MapView)

@zugaldia
Copy link
Member

cc: @tobrun for extra 👀 .

@peterneubauer
Copy link

peterneubauer commented Jan 30, 2017

anything you can see @tobrun @zugaldia ? Feel free to build the branch and try it out!

@tobrun
Copy link
Member

tobrun commented Jan 30, 2017

Thanks for the feedback. I've been able to look at the branch and reproduce the issue. Since v4.2.0 we've changed our rendering component from TextureView to SurfaceView (for performance reasons). While both allow showing OpenGL content, SurfaceView gives you a dedicated drawing surface while TextureView will draw the content to a Texture. The issue you are running into is related to having both a WebView and a SurfaceView in one screen (the WebView has it's own surface).

For now, a workaround is to switch to TextureView by enabling it in the XML:

mapbox:texture_mode="true"

Longer term, we're working on moving to a GlSurfaceView #5766 (to improve rendering performance further) and we'd appreciate you test your app with it once this released to identify any potential regressions (TextureView is deprecated and will be removed once GlSurfaceView is stable). Finally, please make sure to upgrade to v4.2.2 when you have a chance (we've made a few improvements to our gesture handling and included multiple bug fixes).

@tobrun tobrun closed this as completed Jan 30, 2017
@rsahlin
Copy link

rsahlin commented Jan 30, 2017

Hi @tobrun and thanks for the swift reply!

Great, I'll update to 4.2.2 tomorrow and test with the specified parameter.
I'll follow migration to GLSurfaceView with anticipation :-)

Best regards
/Richard

@rsahlin
Copy link

rsahlin commented Jan 31, 2017

Hi @tobrun

I have now checked using 4.2.2 and mapbox:texture_mode="true" in the XML.
Still getting the EGL_BAD_DISPLAY crash, this is regardless if the preview texture view is present or not.

Please let me know if there is anything I can do to help you.

/Richard

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants