OpenVidu android project crashes when leaving the session!

Hi Guys, I am trying to fix this issue that persists in the OpenVidu android doc. When I try to leave the session the app crashes with the below stacktrace.

------------- Stacktrace ----------------
2020-05-13 18:37:11.268 16277-18122/in.app.chirpz I/org.webrtc.Logging: WebRtcAudioTrackExternal: Stopping the AudioTrackThread…
2020-05-13 18:37:11.287 16277-18108/in.app.chirpz E/org.webrtc.Logging: EglRenderer: Exception on EglRenderer thread
2020-05-13 18:37:11.288 16277-18108/in.app.chirpz E/org.webrtc.Logging: EglRenderer: java.lang.RuntimeException: glUseProgram: GLES20 error: 1282
2020-05-13 18:37:11.288 16277-18108/in.app.chirpz E/org.webrtc.Logging: EglRenderer: java.lang.RuntimeException: glUseProgram: GLES20 error: 1282
at org.webrtc.GlUtil.checkNoGLES2Error(GlUtil.java:37)
at org.webrtc.GlShader.useProgram(GlShader.java:118)
at org.webrtc.GlGenericDrawer.prepareShader(GlGenericDrawer.java:246)
at org.webrtc.GlGenericDrawer.drawOes(GlGenericDrawer.java:159)
at org.webrtc.GlRectDrawer.drawOes(GlRectDrawer.java:14)
at org.webrtc.VideoFrameDrawer.drawTexture(VideoFrameDrawer.java:40)
at org.webrtc.VideoFrameDrawer.drawFrame(VideoFrameDrawer.java:213)
at org.webrtc.EglRenderer.renderFrameOnRenderThread(EglRenderer.java:662)
at org.webrtc.EglRenderer.lambda$vWDJEj1GWjHSjwoQQjEEK_IVOJE(Unknown Source:0)
at org.webrtc.-$$Lambda$EglRenderer$vWDJEj1GWjHSjwoQQjEEK_IVOJE.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at org.webrtc.EglRenderer$HandlerWithExceptionCallback.dispatchMessage(EglRenderer.java:103)
at android.os.Looper.loop(Looper.java:201)
at android.os.HandlerThread.run(HandlerThread.java:65)
2020-05-13 18:37:11.290 16277-18108/in.app.chirpz E/AndroidRuntime: FATAL EXCEPTION: local_gl_surface_viewEglRenderer
Process: in.app.chirpz, PID: 16277
java.lang.RuntimeException: glUseProgram: GLES20 error: 1282
at org.webrtc.GlUtil.checkNoGLES2Error(GlUtil.java:37)
at org.webrtc.GlShader.useProgram(GlShader.java:118)
at org.webrtc.GlGenericDrawer.prepareShader(GlGenericDrawer.java:246)
at org.webrtc.GlGenericDrawer.drawOes(GlGenericDrawer.java:159)
at org.webrtc.GlRectDrawer.drawOes(GlRectDrawer.java:14)
at org.webrtc.VideoFrameDrawer.drawTexture(VideoFrameDrawer.java:40)
at org.webrtc.VideoFrameDrawer.drawFrame(VideoFrameDrawer.java:213)
at org.webrtc.EglRenderer.renderFrameOnRenderThread(EglRenderer.java:662)
at org.webrtc.EglRenderer.lambda$vWDJEj1GWjHSjwoQQjEEK_IVOJE(Unknown Source:0)
at org.webrtc.-$$Lambda$EglRenderer$vWDJEj1GWjHSjwoQQjEEK_IVOJE.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at org.webrtc.EglRenderer$HandlerWithExceptionCallback.dispatchMessage(EglRenderer.java:103)
at android.os.Looper.loop(Looper.java:201)
at android.os.HandlerThread.run(HandlerThread.java:65)

Is there a solution for this?

Thanks in advacne!

The official Android tutorial has the problem you reported?

Have you tested with several terminals? Can you share with us platform version you are using.

We have never seen this problem before. Does it happen in all the Android devices you are testing? In which specific phone model does it occur? Have you made any change at all at official OpenVidu Android tutorial? The only thing I have found online similar to your issue is something related to hardware acceleration: https://stackoverflow.com/questions/47118620/webrtc-application-crash-on-samsung-galaxy-j1-4g

Hi micael.gallego, thanks for the reply!

Yes I am using the OpenVidu Android tutorial doc and the git project “https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-android”.

I am using Redmi Note 6 Pro. This crash also happens in One Plus 6T.

Gradle info
Build tools: 29.0.2
compile SDK: 29
minSdkVersion 23
targetSdkVersion 29

dependencies {
implementation fileTree(dir: ‘libs’, include: [’*.jar’])

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

implementation 'com.jakewharton:butterknife:10.2.0'
implementation 'com.squareup.okhttp3:okhttp:4.2.0'

implementation 'com.neovisionaries:nv-websocket-client:2.9'
implementation 'org.webrtc:google-webrtc:1.0.28513'

annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
implementation 'com.google.firebase:firebase-auth:19.3.1'
implementation 'com.facebook.android:facebook-android-sdk:5.15.3'
implementation 'com.google.android.gms:play-services-auth:18.0.0'

implementation('io.socket:socket.io-client:0.8.3') {
    // excluding org.json which is provided by Android
    exclude group: 'org.json', module: 'json'
}
implementation 'com.google.android.material:material:1.1.0'

implementation 'com.google.firebase:firebase-storage:19.1.1'
implementation 'com.google.firebase:firebase-database:19.3.0'

implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

}

Hi pabloFuente thanks for the response!

Yes I am using the OpenVidu Android tutorial doc and the git project “https://github.com/OpenVidu/openvidu-tutorials/tree/master/openvidu-android”.

I am using Redmi Note 6 Pro, when I leave the session the app crashes and I get the above log. This crash also happens in One Plus 6T.

I have also set hardware acceleration to false in the Manifest for the activity & the application.

Does the error happen if you use our demo server? (https://demos.openvidu.io:443/) (MY_SECRET)

I understand from your previous response that you have not modified the Android tutorial in any way, and that you just followed the running steps in the documentation.

Tell me the exact steps I must follow to trigger the error. When I say exact, I mean exact:

  1. Does the error happens when the Android user is the only one connecting and disconnecting from a session? If not, how many users are connected to the session? Which platforms are they using? Are they using a particular OpenVidu tutorial?
  2. Are all they publishing and subscribing?
  3. Which is the order of the users joining the session?
  4. When you leave the session in the Android app, is the first user leaving the session?

And any other information you think is relevant to replicate the issue.

Hi pabloFuente thanks for the reply!

No this error does not occur when I use your demo server.

  1. Does the error happens when the Android user is the only one connecting and disconnecting from a session? If not, how many users are connected to the session? Which platforms are they using? Are they using a particular OpenVidu tutorial?

—> Yes the app crashes when the last person in the room tries to leave the session.

  1. Are all they publishing and subscribing?

—> Yes

  1. Which is the order of the users joining the session?

—> First I create
—> Then add my friend to the call by sharing the room name

  1. When you leave the session in the Android app, is the first user leaving the session?

—> When I leave the session, only I leave the session. The first user still remains in the session until he leaves the session manually.

Is there any configuration that we must do when we deploy the OpenVidu server(We followed the steps provided in the tutorial for deploying)? or have we missed anything?

Hi pabloFuente, is there any work around/solution for the crash that happens when the last user tries to exit the session?

I really need some guidance here! Awaiting your response!

We need a way to reproduce the error ourselves.

If the error doesn’t happen in our demo server, is really hard for us to reproduce it.

If you share the details of your deployment (you can send a private message to openvidu@gmail.com) we can test the code with it to learn what is the root cause.

Hi micael.gallego,

Thank you the response!

Yes, we will share the details of deployment with you over the mentioned email.

Please give us a days time so that we can share it via email.

Hi micael.gallego,

After digging a lot I found out that the above error “EglRenderer: java.lang.RuntimeException: glUseProgram: GLES20 error: 1282” says “OpenGL outofmemoryexception”.

I have now set the heap memory to 4g and the crash has reduced but the issue in itself is not resolved.

Can you please let me know what can be done to handle “outofmemoryexception” in the app?

It is a general Android question. Please use an Android related forum for that.

Are you using an emulator or a real Android device?

I am using a real android device.

Hi, I am facing the same issue. Have you found a solution for this?

I am facing the same issue :frowning:
Edit: I think it is because the leaveSession() function is called several times, in onStop, onDestroy and in onBackPressed.

Hi @Raphael,

Below changes stoped the crash. Basically it was a memory issue at the point of leave session.

Add android:hardwareAccelerated=“false” to the SessionActivity.

In SessionAcivity.java

public void leaveSession() {
        try{
            AsyncTask.execute(() -> {
                websocket.setWebsocketCancelled(true);
                if (websocket != null) {
                    websocket.leaveRoom();
                    websocket.disconnect();
                }
                localParticipant.dispose();
            });

            activity.runOnUiThread(() -> {
                for (RemoteParticipant remoteParticipant : remoteParticipants.values()) {
                    if (remoteParticipant.getPeerConnection() != null) {
                        remoteParticipant.getPeerConnection().close();
                    }
                    views_container.removeView(remoteParticipant.getView());
                }
                activity.localVideoView.clearImage();
            });

            AsyncTask.execute(() -> {
                if (peerConnectionFactory != null) {
                    peerConnectionFactory.dispose();
                    peerConnectionFactory = null;
                }
            });
        }catch (Exception e){
            e.printStackTrace();
        }
    }  

When the app tries to disconnect the websocket it needs some time and this need not run on UI thread along with removal of peerconnectionfactory in loop. Loops if not pushed to a separate thread will cause the UI to freeze and the OS will try to kill the app.

Hope this helps!

4 Likes