| Summary: | Software renderer no longer renders after Android screen orientation change | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Michael Davies <a1studmuffin> |
| Component: | render | Assignee: | Sylvain <sylvain.becker> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | 2.0.5 | ||
| Hardware: | ARM | ||
| OS: | Android (All) | ||
| Attachments: | patch | ||
There's some discussion on this bug here: https://www.reddit.com/r/sdl/comments/5sr8q6/sdl2_android_bugs_with_hardware/ Sylvain, is this fixed in 2.0.6? 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.
Created attachment 2833 [details]
patch
Patch for testdrawchessboard
It can be reproduced on desktop when using the SDL_WINDOW_RESIZABLE flag and resizing the window manually.
Fixed, thanks! https://hg.libsdl.org/SDL/rev/daea00fb0938 |
I've discovered a problem with the software renderer on Android that has a 100% repro rate in the testdrawchessboard.c sample app. If you compile and run the testdrawchessboard.c sample app on an Android device, then rotate the device, after the app refreshes the screen to match the orientation, the software renderer no longer updates. The app is still running in the background, but what's on screen appears frozen. This will persist until the app is restarted. The same behaviour occurs if I lock and unlock the screen instead of rotating the device. Unfortunately the testdrawchessboard.c sample app draws a static image, so it's very easy to miss this bug. :) To make the sample app draw a dynamic image instead, inside DrawChessboard() change this line: SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0xFF); to this: SDL_SetRenderDrawColor(renderer, rand()%255, rand()%255, rand()%255, 0xFF); Tested on an HTC One M8 (Android 7.1.1) and Samsung Galaxy Note 4 (Android 6), compiled with Android SDK 24 NDK 13.1. I have observed this behaviour in SDL 2.0.5 and in Mercurial tip revision as of February 15th 2017.