SDL2 Android: Issue rotating screen with software renderer


#1

Hi there,

I’m using SDL 2.0.5 and the Android project template to port an existing SDL2 game to Android.

I’m seeing a problem when using the software renderer on Android. When the surface changes (eg. due to rotating portrait to landscape, or locking + unlocking the screen), the screen goes black and nothing I do recovers the image. The issue does not occur if I use a different renderer (eg. opengles or opengles2). I can tell from debug logging that the game is still running + rendering in the background, but I just can’t see anything on screen. I’ve tried doing an SDL_RenderClear() with a red background to make it obvious where the surface is, but again I see nothing but black after rotating the device or locking/unlocking the screen. I’ve tried tracing through the SDL software renderer code to see if any errors are being generated, but nothing seems to jump out at me.

Is this a known issue, and is there a workaround? I’ve taken a look in Mercurial for any Android-related fixes since 2.0.5 but there doesn’t seem to be anything there. I also couldn’t find any mention of this issue online.

Thanks for your help,
Michael


#2

An update: I’m able to reproduce the problem in the testdrawchessboard.c sample using Mercurial tip code (as of Tuesday February 14th 2017), if I change the renderer creation lines (around line 110) from:

surface = SDL_GetWindowSurface(window);
    renderer = SDL_CreateSoftwareRenderer(surface);

to:

renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE);

Using the original code, when I launch the Android app, I can rotate the screen and the chessboard rotates as expected. Using the modified code, rotating the screen causes everything to go black (excluding the Android nav bar) until I relaunch the app.

My understanding was that either method for creating the software renderer should be fine, but perhaps I’m mistaken?


#3

I will take this silence as speechlessness… but wait, the plot thickens!

I’ve discovered the testdrawchessboard.c sample is actually broken on Android, at least in my environment (latest SDL2 source from Mercurial, Android 7.0 (SDK 24), Android NDK 13.1).

Once the screen rotates, the software renderer no longer updates the screen, but it does keep the last image it rendered hanging around. (As mentioned in the last post, with the second render method I mentioned above, it results in a black screen.) I believe this bug has gone unnoticed because the DrawChessboard method draws a static image, so it’s entirely not obvious when the software renderer breaks and appears as if the sample is working.

If you modify this line in DrawChessboard() from:

SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF);

to

SDL_SetRenderDrawColor(renderer, rand()%255, rand()%255, rand()%255, 0xFF);

it will turn the chessboard into a disco floor, and it will become obvious when the renderer stops updating the screen.