We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5528 - Android black screen on resume using OpenGL ES 2.0
Summary: Android black screen on resume using OpenGL ES 2.0
Status: NEW
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.14
Hardware: ARM Android (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-02 22:01 UTC by Vitaly Novichkov
Modified: 2021-02-04 12:53 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vitaly Novichkov 2021-02-02 22:01:29 UTC
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
Comment 1 Sylvain 2021-02-03 07:21:14 UTC
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
Comment 2 Vitaly Novichkov 2021-02-03 21:50:38 UTC
Oh, interesting, how I messed this up? Gonna try this out... Thanks for the notice!
Comment 3 Vitaly Novichkov 2021-02-03 22:19:12 UTC
btw, does that also counting the rendering into the texture too? Okay, I'll check.
Comment 4 Vitaly Novichkov 2021-02-03 23:16:12 UTC
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
Comment 5 Sylvain 2021-02-04 07:24:08 UTC
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 ?
Comment 6 Vitaly Novichkov 2021-02-04 08:02:26 UTC
> 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
Comment 7 Vitaly Novichkov 2021-02-04 08:32:58 UTC
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.
Comment 8 Vitaly Novichkov 2021-02-04 08:35:03 UTC
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
Comment 9 Vitaly Novichkov 2021-02-04 08:41:00 UTC
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.
Comment 10 Sylvain 2021-02-04 08:48:27 UTC

>> 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, ..
Comment 11 Vitaly Novichkov 2021-02-04 08:55:37 UTC
> 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
Comment 12 Sylvain 2021-02-04 09:15:34 UTC
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 ?
Comment 13 Vitaly Novichkov 2021-02-04 09:47:04 UTC
Closing to the evening (UTC+3) I'll try to compose a simple test program that simulates my and verify the work.
Comment 14 Vitaly Novichkov 2021-02-04 09:52:02 UTC
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
Comment 15 Vitaly Novichkov 2021-02-04 09:54:51 UTC
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?
Comment 16 Vitaly Novichkov 2021-02-04 09:55:33 UTC
I'll try some in the evening after my workday will finish.
Comment 17 Sylvain 2021-02-04 12:26:04 UTC
yep, re-create texture once you get the device reset.
(you don't need to recreate the SDL renderer)
Comment 18 Sylvain 2021-02-04 12:53:31 UTC
Updated the android README file because this is a recurrent issue
http://hg.libsdl.org/SDL/rev/8609e27b3eed

feel free to improve it!