keshav kowshik
keshav kowshik

Reputation: 2374

Failed to create EGL context

I am getting the following crash in few devices and code works fine in few devices. I am not understanding which part of code is creating this crash. It was working fine few days before and all of sudden I am seeing this crash. Can anyone please teach me what might have brought this crash. Please help me

Stack trace is as follows:

java.lang.RuntimeException: java.lang.RuntimeException: Failed to create EGL context: 0x3003                                                                                at org.webrtc.EglBase14.createEglContext(EglBase14.java:260)
at org.webrtc.EglBase14.<init>(EglBase14.java:58)
at org.webrtc.EglBase.create(EglBase.java:86)
at org.webrtc.EglRenderer$3.run(EglRenderer.java:194)
at org.webrtc.ThreadUtils$5.call(ThreadUtils.java:208)
at org.webrtc.ThreadUtils$5.call(ThreadUtils.java:205)
at org.webrtc.ThreadUtils$4.run(ThreadUtils.java:182)
at android.os.Handler.handleCallback(Handler.java:742)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.os.HandlerThread.run(HandlerThread.java:61)
at org.webrtc.ThreadUtils.invokeAtFrontUninterruptibly(ThreadUtils.java:193)
at org.webrtc.ThreadUtils.invokeAtFrontUninterruptibly(ThreadUtils.java:205)
at org.webrtc.EglRenderer.init(EglRenderer.java:183)
at org.webrtc.SurfaceViewRenderer.init(SurfaceViewRenderer.java:101)
at org.webrtc.SurfaceViewRenderer.init(SurfaceViewRenderer.java:82)
at com.twilio.video.VideoView.setupRenderer(VideoView.java:158)
at com.twilio.video.VideoView.onAttachedToWindow(VideoView.java:91)
at android.view.View.dispatchAttachedToWindow(View.java:14538)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2844)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2844)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2844)
at android.view.ViewGroup.addViewInner(ViewGroup.java:4349)
at android.view.ViewGroup.addView(ViewGroup.java:4146)
at android.view.ViewGroup.addView(ViewGroup.java:4087)
at android.support.v7.widget.RecyclerView$5.addView(RecyclerView.java:676)
at android.support.v7.widget.ChildHelper.addView(ChildHelper.java:107)
at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:7399)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:7357)
at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:7345)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1459)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1408)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:580)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3374)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2901)
at android.view.View.measure(View.java:18811)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1112)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:632)
at android.view.View.measure(View.java:18811)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
at android.view.View.measure(View.java:18811)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
at android.view.View.measure(View.java:18811)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:716)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:462)
at android.view.View.measure(View.java:18811)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
at android.view.View.measure(View.java:18811)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5952)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
at android.widget.LinearLayout.onM

Upvotes: 5

Views: 6560

Answers (3)

Had the same issue, and on different devices the number of connections before failure was different. But solved it. it was an error in the order of dispose methods of all the webrtc objects. This order ended up working for me. - Im using it for screen mirroring to another device, might be slightly different for cameras.

This is a pseudocode. in reality all the calls are in separate try catches and null checks, in case something was already disposed off or is called more then once.

And all in new thread, cannot be called from connection close handle directly else it hangs or crashes.

new Thread(() -> {
  VideoCapturer.stopCapture();
  PeerConnection.dispose();
  VideoTrack.dispose();
  VideoSource.dispose();
  AudioTrack.dispose();
  AudioSource.dispose();
  MediaStream.dispose();
  VideoCapturer.dispose();
  SurfaceTextureHelper.dispose();
  PeerConnectionFactory.dipose();
}).start();

Im disposing of entire connection factory, but that can propably be safely reused.

Upvotes: 1

devaga
devaga

Reputation: 376

The problem is related with the number of contexts created. Creating egl context several times leads to this crash on EglBase.create() method when the limit point is reached. Make sure you're not creating so many eglContexts. The limit seems to be 30 on my device.

According to WebRTC's documentation calling .release() should handle that problem, but it unfortunately does not.

Upvotes: 6

polar wu
polar wu

Reputation: 11

You can check this issue on GitHub.

0x3003 is EGL_BAD_ALLOC.

This is known. There is a global EGL context, which we'll leak if you reload the app bundle in debug mode. This does not happen in release mode, since this context will be alive for the lifetime of the application.

Upvotes: -4

Related Questions