diff options
author | Sam Lantinga <slouken@libsdl.org> | 2017-08-13 21:12:14 -0700 |
---|---|---|
committer | Sam Lantinga <slouken@libsdl.org> | 2017-08-13 21:12:14 -0700 |
commit | 868f6e95b8b400be0df93103951b72b8bbdeaad2 (patch) | |
tree | e90139b6a5b830bd09dfb3053dc9974f07ed1b1c | |
parent | 09af6afc6111c0d46e1f291cdf211362f9430582 (diff) |
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.
-rw-r--r-- | test/testdrawchessboard.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/test/testdrawchessboard.c b/test/testdrawchessboard.c index 6aefd48f6e..cef8621fca 100644 --- a/test/testdrawchessboard.c +++ b/test/testdrawchessboard.c @@ -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()); |