Skip to content

Android black screen on resume using OpenGL ES 2.0 #4041

@SDLBugzilla

Description

@SDLBugzilla

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.14
Reported for operating system, platform: Android (All), ARM

Comments on the original bug report:

On 2021-02-02 22:01:29 +0000, Vitaly Novichkov wrote:

Hello!

I found that the bug against the black screen on resuming got back, it happens on various devices:

  • Open the game
  • Switch to another application, try to do anything
  • Try to switch the game back
  • You'll get the black screen
  • However, the game itself will resume its normal work, but a black screen
  • No matter what to draw: textures or color-filled shapes
  • I do render into texture, then into the screen. Also, I draw some shapes on the screen directly.
    This happens on Android 4.1, 5.1, Android 10, also on Android 8 the bug confirmed.

At the logger I get the next spamming:

02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/libEGL: eglMakeCurrent:777 error 3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/libEGL: eglMakeCurrent:777 error 3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/libEGL: eglMakeCurrent:777 error 3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/libEGL: eglMakeCurrent:777 error 3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/libEGL: eglMakeCurrent:777 error 3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/libEGL: eglMakeCurrent:777 error 3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/libEGL: eglMakeCurrent:777 error 3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/libEGL: eglMakeCurrent:777 error 3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/libEGL: eglMakeCurrent:777 error 3002 (EGL_BAD_ACCESS)
02-03 00:55:02.482 3666-3690/ru.wohlsoft.thextech.debug E/EGL_emulation: tid 3690: eglMakeCurrent(1500): error 0x3002 (EGL_BAD_ACCESS)


If needed, I can try to compose a simple unit test that reproduces this bug

On 2021-02-03 07:21:14 +0000, Sylvain wrote:

Did you make sure not to call any rendering function between the two events
SDL_WILL_ENTER_BACKGROUND and SDL_DID_ENTER_FOREGROUND

see docs/README-android.md

On 2021-02-03 21:50:38 +0000, Vitaly Novichkov wrote:

Oh, interesting, how I messed this up? Gonna try this out... Thanks for the notice!

On 2021-02-03 22:19:12 +0000, Vitaly Novichkov wrote:

btw, does that also counting the rendering into the texture too? Okay, I'll check.

On 2021-02-03 23:16:12 +0000, Vitaly Novichkov wrote:

Nope, that didn't help completely, even I made the strict avoiding of any render functions being called, I still can get the black screen and the EGL_BAD_ACCESS error after I switched application back

On 2021-02-04 07:24:08 +0000, Sylvain wrote:

that really really is a reason,
are you depleting the event loop ?
no multi-threading ?

really stop using renderer after reading WILL_ENTER_BG, and start again using DID_ENTER_FG.

are you using the SDL_Renderer or your own context ?

On 2021-02-04 08:02:26 +0000, Vitaly Novichkov wrote:

are you depleting the event loop ?

No, I do call the event loop sequentially

no multi-threading ?

No, single threading

really stop using renderer after reading WILL_ENTER_BG, and start again using DID_ENTER_FG.

Oh, I did a mistake - I used the WILL_ENTER_FG instead of WILL_ENTER_BG event, I should re-try this experiment again.

are you using the SDL_Renderer or your own context ?

I use SDL_Renderer

On 2021-02-04 08:32:58 +0000, Vitaly Novichkov wrote:

Okay, I really made sure no render will be called between those events, I even added asserts to crash if any of the render calls will be executed after SDL_APP_WILLENTERBACKGROUND event, and allow them to be called after SDL_APP_DIDENTERFOREGROUND event that unlocks the render.

On 2021-02-04 08:35:03 +0000, Vitaly Novichkov wrote:

The result is the same, on Android 10:

  • open the game
  • switch another application (my log will print the fact "SDL_APP_WILLENTERBACKGROUND" was coming, I made sure those messages be printed to see the result)
  • All big render calls got blocked by a boolean
  • All small routine render calls got blocked by assert
  • Switch the game back (my log will print the fact of "SDL_APP_DIDENTERFOREGROUND")
  • Black screen

On 2021-02-04 08:41:00 +0000, Vitaly Novichkov wrote:

I also checked the fact of any attempts to call the render calls, just by spamming of the same message into the log, the spamming is off completely when entering background, and getting on back when entered background.

On 2021-02-04 08:48:27 +0000, Sylvain wrote:

are you depleting the event loop ?
No, I do call the event loop sequentially

before each frame, and also periodically, you must poll all the events.

Just to make sure, all functions using the SDL_renderer includes: RenderCopy, RenderPresent, CreateTexture, UpdateTexture, ..

On 2021-02-04 08:55:37 +0000, Vitaly Novichkov wrote:

before each frame, and also periodically, you must poll all the events.

Yes, that what I already do, I poll all events in every loop cycle

Just to make sure, all functions using the SDL_renderer includes:

CreateTexture, UpdateTexture
I don't call them during the loop except for the lazy-decompression algorithm that gets executed when calling the big render call, I blocked by the boolean

RenderCopy, RenderPresent
Both blocked by the boolean I do set

On 2021-02-04 09:15:34 +0000, Sylvain wrote:

This look strange ...

you have recent SDL2 lib + sync'ed java file ?

you can add trace here:
http://hg.libsdl.org/SDL/file/1cde3dd0f44d/src/video/android/SDL_androidevents.c
to backup and restore context

maybe log the event: SDL_RENDER_DEVICE_RESET

with those print do you have a full adb log to check ?

try with a simpler test case ?

On 2021-02-04 09:47:04 +0000, Vitaly Novichkov wrote:

Closing to the evening (UTC+3) I'll try to compose a simple test program that simulates my and verify the work.

On 2021-02-04 09:52:02 +0000, Vitaly Novichkov wrote:

Anyway, without of SDL2 patching, I did the tracking of SDL_RENDER_DEVICE_RESET event, and I got next:

02-04 12:50:08.444 2791-2814/ru.wohlsoft.thextech.debug D/TRACKERS: Android: Entering background
02-04 12:50:16.879 2791-2814/ru.wohlsoft.thextech.debug D/TRACKERS: Android: Resumed foreground
02-04 12:50:19.591 2791-2814/ru.wohlsoft.thextech.debug D/TRACKERS: Android: Entering background
02-04 12:50:23.807 2791-2814/ru.wohlsoft.thextech.debug D/TRACKERS: Android: Resumed foreground
02-04 12:50:27.021 2791-2814/ru.wohlsoft.thextech.debug D/TRACKERS: Android: Entering background
02-04 12:50:32.787 2791-2814/ru.wohlsoft.thextech.debug D/TRACKERS: Android: Resumed foreground
02-04 12:50:32.787 2791-2814/ru.wohlsoft.thextech.debug D/TRACKERS: Android: Render Device Reset

I had multiple times to go into the background, and then, resume back, but the thing got blacked once SDL_RENDER_DEVICE_RESET was happened at my log

On 2021-02-04 09:54:51 +0000, Vitaly Novichkov wrote:

So, seems once this event came:


SDL_RENDER_TARGETS_RESET

the render targets have been reset and their contents need to be updated (>= SDL 2.0.2)

SDL_RENDER_DEVICE_RESET

the device has been reset and all textures need to be recreated (>= SDL 2.0.4)

I should reload all the textures again, right?

On 2021-02-04 09:55:33 +0000, Vitaly Novichkov wrote:

I'll try some in the evening after my workday will finish.

On 2021-02-04 12:26:04 +0000, Sylvain wrote:

yep, re-create texture once you get the device reset.
(you don't need to recreate the SDL renderer)

On 2021-02-04 12:53:31 +0000, Sylvain wrote:

Updated the android README file because this is a recurrent issue
http://hg.libsdl.org/SDL/rev/8609e27b3eed

feel free to improve it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions