pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.55k stars 773 forks source link

Crash at ManagerRender.drawScreen #744

Open insidefun opened 3 years ago

insidefun commented 3 years ago

RTMP, OpenGlView, No filters, Front camera

Fatal Exception: java.lang.RuntimeException: drawScreen end. GL error: 1285
       at com.pedro.encoder.utils.gl.GlUtil.checkGlError(GlUtil.java:126)
       at com.pedro.encoder.input.gl.render.ScreenRender.draw(ScreenRender.java:115)
       at com.pedro.encoder.input.gl.render.ManagerRender.drawScreen(ManagerRender.java:66)
       at com.pedro.rtplibrary.view.OpenGlView.run(OpenGlView.java:144)
       at java.lang.Thread.run(Thread.java:929)
pedroSG94 commented 3 years ago

That error means OutOfMemory. Do you have any way to reproduce it? Do you have this error with all devices?

insidefun commented 3 years ago

image

Based on firebase info, devices had enought memory

pedroSG94 commented 3 years ago

Acording with android documentation 1285 is out of memory: https://developer.android.com/reference/android/opengl/GLES20#GL_OUT_OF_MEMORY

The question is, why only in certains devices? Do you have any way to know if your user is streaming long time before get this crash? Maybe I'm not releasing something properly

linean commented 2 years ago

I'm facing a similar issue mostly on Samsung devices

image
Fatal Exception: java.lang.RuntimeException: drawScreen end. GL error: 1285
       at com.pedro.encoder.utils.gl.GlUtil.checkGlError(GlUtil.java:142)
       at com.pedro.encoder.input.gl.render.ScreenRender.draw(ScreenRender.java:131)
       at com.pedro.encoder.input.gl.render.ManagerRender.drawScreen(ManagerRender.java:76)
       at com.pedro.rtplibrary.view.OpenGlView.run(OpenGlView.java:189)
       at java.lang.Thread.run(Thread.java:764)

After debugging with the Android Studio profiler I didn't find any leaks 😞

pedroSG94 commented 2 years ago

Hello,

If possible, let me know if you are using any filter and which one. Also, if you can get time streaming until you get that crash, device model and android api.

This crash seems really difficult to reproduce and I'm not sure about the reason so it is hard to fix.

linean commented 2 years ago

I'm using BlurFilterRender. These crashes are not super frequent so from my perspective it's a low prio thing.

Based on the logs, crashes are pretty random. Sometimes they occur after a few seconds of streaming and somethimes after user leaves the screen. It's also possible that these are caused by other leakage elsewhere in the application 🤷

If I manage to find some pattern or more details I'll post them here 🤞

MrAlanWei commented 2 years ago

@linean Have you solved it? I have the same problem

linean commented 2 years ago

Unfortunately no, crashes seems pretty random. Luckily they doesn't affect a significant number of users 🤷

pedroSG94 commented 2 years ago

If anyone could find a way to reproduce the error report it here. Since in OpenGL documentation the error code is an out of memory I only can assume a GPU memory overflow. If you have any way to report GPU memory state when you receive that error, this could be helpful

minonger commented 2 years ago

I have the same error on Samsung Galaxy S21. It's happen all the time. Without any filter. openGL_crash-01

mkrn commented 1 year ago

@minonger were you able to fix it? Are there any special conditions to it happening? Like using WiFi/5G / reconnecting / going to background and back?

altunbayrakergun commented 8 months ago

Have you solved it? I'm facing this problem now. I'm using both ImageFilter and TextFilter together. App still in development. There were no problems in short-term tests. I suddenly encountered this error while broadcasting for more than 20 minutes. Test device is Redmi Note 11 pro. 3.5gb free memory and 35gb available disk. I'm using mobile internet.

pedroSG94 commented 8 months ago

Hello,

This error is really random and I'm not able to reproduce it consistently to solve.

If you can reproduce it, test this and tell me the result:

Remember that this is an out of memory. Can you check the GPU memory usage? Maybe you can find a pattern

altunbayrakergun commented 8 months ago

Thank you for quick reply @pedroSG94 . Tests still continue. So propably I'll reproduce it. App currently doesn't support rotation. It only supports landscape and only streams foreground. I thought maybe the behavior was being disrupted for a reason like "preventing accidental screen touching". I'll let you know immediately when reproduce it again.

pedroSG94 commented 7 months ago

Hello,

I did a refactor to GlInterface (OpenGlView and GlStreamInterface) that maybe solved this error. If possible try update the libary to version 2.4.0 and let me know if the problem is solved or reduced.

altunbayrakergun commented 7 months ago

I followed the user experience for a while and found the error. The activity was set to sensorlandscape. This error occurred when the user made a movement that caused a 180-degree rotation while holding the device. After changing the sensorlandscape setting to landscape, the problem disappeared. Also thank you for your revision. I will include it in the next refactoring process.

altunbayrakergun commented 7 months ago

It is worth adding that the problem only occurred if the screen was rotated while using filters. There is no problem with rotation when there is no filter.

Feureth commented 7 months ago

Hi @pedroSG94, Today I have found that this issue occurs for AndroidViewFilterRender, if it has isHardwareMode forced to be false. I've not checked any other filter, my orientation is always horizontal. I hope, it will help you with finding solution.

pedroSG94 commented 7 months ago

Hello,

@Feureth are you using library version 2.4.0?

Feureth commented 7 months ago

Yes

linean commented 3 months ago

GL error: 1285 is gone for me in 2.4.3 but now I observe GL error: 1281. Here are some example stack traces

   Fatal Exception: java.lang.RuntimeException: drawCamera start. GL error: 1281
       at com.pedro.encoder.utils.gl.GlUtil.checkGlError(GlUtil.java:144)
       at com.pedro.encoder.input.gl.render.CameraRender.draw(CameraRender.java:95)
       at com.pedro.encoder.input.gl.render.MainRender.drawOffScreen(MainRender.kt:58)
       at com.pedro.library.view.OpenGlView.draw(OpenGlView.java:242)
       at com.pedro.library.view.OpenGlView.lambda$onFrameAvailable$6(OpenGlView.java:347)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:764)
Fatal Exception: java.lang.RuntimeException: initGl end. GL error: 1281
       at com.pedro.encoder.utils.gl.GlUtil.checkGlError(GlUtil.java:144)
       at com.pedro.encoder.input.gl.render.filters.BaseFilterRender.initGl(BaseFilterRender.java:51)
       at com.pedro.encoder.input.gl.render.MainRender.addFilter(MainRender.kt:99)
       at com.pedro.encoder.input.gl.render.MainRender.setFilterAction(MainRender.kt:148)
       at com.pedro.library.view.OpenGlView.draw(OpenGlView.java:251)
       at com.pedro.library.view.OpenGlView.lambda$onFrameAvailable$6(OpenGlView.java:347)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
       at java.lang.Thread.run(Thread.java:923)
pedroSG94 commented 3 months ago

Hello,

That error is GL_INVALID_VALUE. Normally produced because a parameter is invalid. Do you have more info about the error? can you reproduce it?

Fatal Exception: java.lang.RuntimeException: initGl end. GL error: 1281 at com.pedro.encoder.utils.gl.GlUtil.checkGlError(GlUtil.java:144) at com.pedro.encoder.input.gl.render.filters.BaseFilterRender.initGl(BaseFilterRender.java:51) at com.pedro.encoder.input.gl.render.MainRender.addFilter(MainRender.kt:99) at com.pedro.encoder.input.gl.render.MainRender.setFilterAction(MainRender.kt:148) at com.pedro.library.view.OpenGlView.draw(OpenGlView.java:251) at com.pedro.library.view.OpenGlView.lambda$onFrameAvailable$6(OpenGlView.java:347) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923)

In this case the error is produced adding a filter. Do you know the filter used in this case and possible values?

linean commented 3 months ago

Unfortunately I'm not able to reproduce it. It happens to less than 0,1% of all users so it's not that bad. I'm using BlurFilterRender.

It seems to happen more on older devices.

image
pedroSG94 commented 3 months ago

Seems that the error is usually in Samsung devices. Can you show me device models? Same with the error (java.lang.RuntimeException: drawCamera start. GL error: 1281)

linean commented 3 months ago

Sure

image image image
pedroSG94 commented 3 months ago

Ok, I will try investigate it. According with internet, this maybe is an error compiling the shader but it has no sense for me (in that case this should crash always in that model). Maybe an error reading the shader from disk?

linean commented 3 months ago

I didn't dive deep into the implementation details, so I'm not able to tell. I'm not really bothered by this crash, but I thought I'd share that 1285 turned into 1281 😇

pedroSG94 commented 3 months ago

Any crash report is really welcome and know that the error 1285 is gone are good news. I hope that, this error (1281) is less frequent than the other (1285). In this case, at least, it is a step in the good direction. :)

pedroSG94 commented 3 months ago

I updated the library with a fix that could help for this case. instead of let opengl fail after create shaders and programs, now the library will throw an error depend of the moment that opengl fail, this way we can get more info about the error 1281 and fix it in nexts commits. Try to update the library to version 2.4.7