Fixed bug 3605 - Software renderer no longer renders after Android screen orientation change

Sylvain

This still happens with the current trunk version.  (software renderer of testdrawchessboard.c)

When there is a rotation, the window size changed and the internal surface is marked as "surface_valid == SDL_FALSE".
And all further call fails.

SDL_video.c :

2478 void
2479 SDL_OnWindowResized(SDL_Window * window)
2480 {
2481     window->surface_valid = SDL_FALSE;
2482     SDL_SendWindowEvent(window, SDL_WINDOWEVENT_SIZE_CHANGED, window->w, window->h);
2483 }

some error set to :
2233         return SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface");


So, this seems to be the behavior of the API ...


In the loop() function of testdrawchessboard.c, we can recreate the surface/renderer :

 65        if (e.type == SDL_WINDOWEVENT)
 66        {
 67             if (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
 68             {
 69                surface = SDL_GetWindowSurface(window);
 70                renderer = SDL_CreateSoftwareRenderer(surface);
 71             }
 72             /* Clear the rendering surface with the specified color */
 73             SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
 74             SDL_RenderClear(renderer);
 75        }

And it displays correctly.
This commit is contained in:
Sam Lantinga 2017-08-13 21:12:14 -07:00
parent 3cae0c38d2
commit 93a520b385

View File

@ -25,6 +25,7 @@
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Surface *surface;
int done;
void
@ -59,7 +60,20 @@ loop()
{
SDL_Event e;
while (SDL_PollEvent(&e)) {
if (e.type == SDL_QUIT) {
/* Re-create when window has been resized */
if ((e.type == SDL_WINDOWEVENT) && (e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) {
SDL_DestroyRenderer(renderer);
surface = SDL_GetWindowSurface(window);
renderer = SDL_CreateSoftwareRenderer(surface);
/* Clear the rendering surface with the specified color */
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear(renderer);
}
if (e.type == SDL_QUIT) {
done = 1;
#ifdef __EMSCRIPTEN__
emscripten_cancel_main_loop();
@ -86,8 +100,6 @@ loop()
int
main(int argc, char *argv[])
{
SDL_Surface *surface;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
@ -100,7 +112,7 @@ main(int argc, char *argv[])
/* Create window and renderer for given surface */
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
window = SDL_CreateWindow("Chess Board", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_RESIZABLE);
if(!window)
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Window creation fail : %s\n",SDL_GetError());