summaryrefslogtreecommitdiff
path: root/test/testdrawchessboard.c
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2017-08-13 21:12:14 -0700
committerSam Lantinga <slouken@libsdl.org>2017-08-13 21:12:14 -0700
commit12e7e0dfa1316c3412d33a5cf32bca2a70e07b05 (patch)
treeb4836990ca80fb81bb6fdb50a3a317763e4c0a32 /test/testdrawchessboard.c
parent982c5e3bd0e77475ecf8ab76a81b89a219e99f6a (diff)
downloadsdl-12e7e0dfa1316c3412d33a5cf32bca2a70e07b05.tar.gz
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.
Diffstat (limited to 'test/testdrawchessboard.c')
-rw-r--r--test/testdrawchessboard.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/test/testdrawchessboard.c b/test/testdrawchessboard.c
index 6aefd48f6..cef8621fc 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());