0

I followed this tutorial in order to capture a video of my game, and it's working. I tested on several devices, and it's working. But it fails with a Nexus 7 (2012). The game freezes.

Debugging the library, I found that the call to EGL14.eglMakeCurrent in line 143 of this file is causing it.

Why EGL14.eglMakeCurrent call may block the execution?

EDIT: There is nothing in logcat when game freezes. I can only get this information from adb bugreport:

"Thread-597" prio=5 tid=76 Native
  | group="main" sCount=1 dsCount=0 obj=0x12d44190 self=0x80858858
  | sysTid=7984 nice=0 cgrp=apps sched=0/0 handle=0x80858d38
  | state=S schedstat=( 43302000 35740000 115 ) utm=2 stm=2 core=3 HZ=100
  | stack=0x80c74000-0x80c76000 stackSize=1036KB
  | held mutexes=
  native: #00 pc 00012444  /system/lib/libc.so (syscall+28)
  native: #01 pc 0001641b  /system/lib/libc.so (???)
  native: #02 pc 000167b1  /system/lib/libc.so (pthread_mutex_lock+310)
  native: #03 pc 00005b5c  /system/lib/libnvos.so (???)
  native: #04 pc 0000a7d8  /system/lib/egl/libGLESv2_tegra.so (???)
  native: #05 pc 00006ee3  /system/lib/egl/libEGL_tegra.so (???)
  native: #06 pc 00006f8f  /system/lib/egl/libEGL_tegra.so (???)
  native: #07 pc 000077db  /system/lib/egl/libEGL_tegra.so (eglMakeCurrent+34)
  native: #08 pc 0000ffc1  /system/lib/libEGL.so (android::egl_display_t::makeCurrent(android::egl_context_t*, android::egl_context_t*, void*, void*, void*, void*, void*, void*)+142)
  native: #09 pc 000125cf  /system/lib/libEGL.so (eglMakeCurrent+266)
  native: #10 pc 0005fffb  /system/lib/libandroid_runtime.so (???)
  native: #11 pc 00271ed3  /data/dalvik-cache/arm/system@framework@boot.oat (Java_com_google_android_gles_1jni_EGLImpl_eglMakeCurrent__Ljavax_microedition_khronos_egl_EGLDisplay_2Ljavax_microedition_khronos_egl_EGLSurface_2Ljavax_microedition_khronos_egl_EGLSurface_2Ljavax_microedition_khronos_egl_EGLContext_2+178)
  at com.google.android.gles_jni.EGLImpl.eglMakeCurrent(Native method)
  at com.mycopmany.mypackage.androidvideocapture.SharedContext.doneCurrent(SharedContext.java:104)
  at com.mycopmany.mypackage.androidvideocapture.Capturing$EncodeThread.run(Capturing.java:104)
  - locked <@addr=0x12f01780> (a com.mycopmany.mypackage.androidvideocapture.VideoCapture)

"Thread-602" prio=5 tid=82 Native
  | group="main" sCount=1 dsCount=0 obj=0x12dd5c50 self=0x7f2c42b0
  | sysTid=6302 nice=0 cgrp=apps sched=0/0 handle=0x7f2d5020
  | state=S schedstat=( 17164000 17265000 48 ) utm=0 stm=1 core=1 HZ=100
  | stack=0x81402000-0x81404000 stackSize=1036KB
  | held mutexes=
  native: #00 pc 00012444  /system/lib/libc.so (syscall+28)
  native: #01 pc 0001641b  /system/lib/libc.so (???)
  native: #02 pc 000167b1  /system/lib/libc.so (pthread_mutex_lock+310)
  native: #03 pc 00005b5c  /system/lib/libnvos.so (???)
  native: #04 pc 0000b64c  /system/lib/egl/libGLESv2_tegra.so (???)
  native: #05 pc 00007219  /system/lib/egl/libEGL_tegra.so (???)
  native: #06 pc 000077db  /system/lib/egl/libEGL_tegra.so (eglMakeCurrent+34)
  native: #07 pc 0000ff93  /system/lib/libEGL.so (android::egl_display_t::makeCurrent(android::egl_context_t*, android::egl_context_t*, void*, void*, void*, void*, void*, void*)+96)
  native: #08 pc 000125cf  /system/lib/libEGL.so (eglMakeCurrent+266)
  native: #09 pc 00061845  /system/lib/libandroid_runtime.so (???)
  native: #10 pc 009bf213  /data/dalvik-cache/arm/system@framework@boot.oat (Java_android_opengl_EGL14_eglMakeCurrent__Landroid_opengl_EGLDisplay_2Landroid_opengl_EGLSurface_2Landroid_opengl_EGLSurface_2Landroid_opengl_EGLContext_2+178)
  at android.opengl.EGL14.eglMakeCurrent(Native method)
  at org.m4m.android.InputSurface.makeCurrent(InputSurface.java:145)
  at org.m4m.android.Surface.<init>(Surface.java:34)
  at org.m4m.android.MediaCodecEncoderPlugin.createInputSurface(MediaCodecEncoderPlugin.java:133)
  at org.m4m.domain.Encoder.getSurface(Encoder.java:34)
  at org.m4m.domain.pipeline.PluginConnector$26.onSurfaceAvailable(PluginConnector.java:354)
  at org.m4m.android.GameCapturerSource.setSurfaceSize(GameCapturerSource.java:52)
  at org.m4m.GLCapture.setSurfaceSize(GLCapture.java:89)
  at com.mycopmany.mypackage.androidvideocapture.VideoCapture.configure(VideoCapture.java:93)
  at com.mycopmany.mypackage.androidvideocapture.VideoCapture.beginCaptureFrame(VideoCapture.java:104)
  at com.mycopmany.mypackage.androidvideocapture.Capturing$EncodeThread.run(Capturing.java:96)
  - locked <@addr=0x12db64a0> (a com.mycopmany.mypackage.androidvideocapture.VideoCapture)
Sergio Viudes
  • 2,714
  • 5
  • 26
  • 44
  • 1
    Check android [log](https://stackoverflow.com/questions/44690357/how-to-read-debug-log-when-using-android/44690501#44690501) and see if there is an exception/error right before it freezes then post it. That should help other people pin-point the issue – Programmer Sep 20 '17 at 11:36
  • There is no error log :( It just freezes – Sergio Viudes Sep 20 '17 at 12:23
  • That would extremely hard to tell the problem without the log. Without the log, it will be possible to debug by those with Nexus 7 (2012) and the app. Sorry that I can't help but note that that will only work with Android 4.3+ devices. It won't work with anything below this. – Programmer Sep 20 '17 at 12:31
  • I know it's hard to tell without the log. I've spent one day and I had no luck... My Nexus 7 had Android 4.4. – Sergio Viudes Sep 20 '17 at 13:03
  • The only thing left is to comment on that tutorial itself. The OP seems to be responding to people. Although I don't know if he/she can help without your log. Just give that a try – Programmer Sep 20 '17 at 13:31
  • Well... the last OP response was 2 years ago. I don't know very much about OpenGL. Maybe an OpenGL expert can tell me why EGL14.eglMakeCurrent can freeze. – Sergio Viudes Sep 20 '17 at 15:52
  • I am no OpenGL expert. Have you tried disabling Android **Multithreaded Rendering** from the Player Settings in the Editor? – Programmer Sep 20 '17 at 16:10
  • Yes, I checked it. It's disabled. – Sergio Viudes Sep 20 '17 at 16:16
  • Enable it and see what happens. I do believe you are getting EGL_BAD_ACCESS but can't really see it for some reason. This looks like a rendering Thread issue to me. It could also be that the context is null. Anyways, nothing else I can do. If you find a solution feel free to post it here. – Programmer Sep 20 '17 at 16:23
  • I enabled it, and I'm getting "Call to OpenGL ES API with no current context" error in another place (when creating a shader). As far I know, it's because rendering is running in another thread. I've checked that context is not null when calling eglMakeCurrent. – Sergio Viudes Sep 20 '17 at 17:13