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 5077 - Black screen on Android with SDL 2.0.12 while 2.0.8 worked fine
Summary: Black screen on Android with SDL 2.0.12 while 2.0.8 worked fine
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: 2.0.12
Hardware: ARM Android (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-04-05 19:53 UTC by Steve Robinson
Modified: 2020-04-07 04:27 UTC (History)
1 user (show)

See Also:


Attachments
Example code (1.10 KB, text/x-csrc)
2020-04-05 19:53 UTC, Steve Robinson
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Robinson 2020-04-05 19:53:23 UTC
Created attachment 4294 [details]
Example code

I went to upgrade my game from SDL 2.0.8 to 2.0.12 and my title screen is now black.

I narrowed it down to the attached example code. The expected behavior is for the screen to be red for three seconds, but instead it's black for three seconds. If I comment out the IMG_Load line, it works fine with both versions of SDL2. I used SDL 2.0.12 and SDL_image 2.0.5. SDL_image was just what I used to make the SDL_Surface that reproduces the error, I don't think this is an SDL_image issue.

I reproduced this on a OnePlus 5 A5000, but never had a problem on LG G4 LGUS991 so it may not happen on just any Android device.

I built ARM64 arch with Android NDK 21 using CMake 3.17.0 to generate a Ninja project and Gradle 6.3 to build the java stuff and make the APK.

This sounds similar to this bug:
https://bugzilla.libsdl.org/show_bug.cgi?id=5011
But I wasn't able to reproduce the problem with my code on macOS so I filed it separately. If you fix that bug, I'd be happy to confirm whether or not it fixes this bug too before you spend time on it :)
Comment 1 Sylvain 2020-04-06 07:01:57 UTC
Hi, can you try to add to your test-case the usual event polling loop ?
Comment 2 Steve Robinson 2020-04-06 15:43:18 UTC
I had the event loop in my actual code, but I put in logic to only render the title screen once because it's completely static. So this example code is representative of that. When I remove that logic and repeatedly render my title screen, it does work. That will likely be my workaround, especially since the title screen will eventually not be static. I still wanted to log the issue because it was a change in behavior and it cost me some time figuring it out.
Comment 3 Sylvain 2020-04-06 16:21:44 UTC
I think it's because of modifications done to prevent other issues of synchronisation between java Activity and the main() thread, and switching pause/resume states.

When the app starts, it switches from start->pause->resume states. Depending on orientation or because of the platform, and you can have small variation of timing, and something it goes several times to pause (eg background) state.

You need to consider that you cannot use the SDL_Renderer and draw while your are in background. And to know whether you are in background/foreground you first need to poll the event loop(). You need to poll, to know if you are in bg or fg. and the loop is blocking just before entering in bg.

If you check your log, I believe, your are trying to draw while the app is still in background.
Comment 4 Steve Robinson 2020-04-07 04:27:23 UTC
Makes sense, thanks for explaining it to me!