Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Patch] [WindowEvent] Clear out RESIZED events on any SIZE_CHANGED event #2949

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.0
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2018-08-13 17:31:45 +0000, Ethan Lee wrote:

Created attachment 3280
Patch to fix loose RESIZED events on SIZE_CHANGED

At the bottom of this post is a test program that demonstrates what's happening, at least on Windows 10.

I'm finding that Windows REALLY likes to dump lots of resize events when toggling fullscreen; in particular it sends a resize event as it's resizing the window, before SDL is finished changing the window size. The result is this:

  • Windows fires RESIZED
  • RESIZED fires SIZE_CHANGED, previous SIZE_CHANGED events cleared
  • Previous RESIZED events cleared
  • SDL sets window size, fires SIZE_CHANGED event, previous SIZE_CHANGED events cleared but RESIZED events are NOT cleared
  • Application polls events, conflicting size events!

On Windows you can actually get a good sense of the problem simply by toggling fullscreen a bunch, no clever setup needed. The way I fixed this is by making it so any SIZE_CHANGED event clears out all of the size events, so whatever the latest size event is the only one in the loop. User resizes will still always get exactly 1 SIZE_CHANGED and 1 RESIZED, but programmatic changes will always get exactly 1 SIZE_CHANGED and 0 RESIZED if they end up overriding any resizes between frames.


#include <SDL.h>

int main(int argc, char **argv)
{
SDL_DisplayMode mode;
SDL_Window *window;
SDL_Event evt;
SDL_bool ftoggle = SDL_FALSE;
Uint8 run = 1;

SDL_Init(SDL_INIT_VIDEO);
SDL_GetCurrentDisplayMode(0, &mode);
window = SDL_CreateWindow(
"WindowEvent Test",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
800,
480,
SDL_WINDOW_SHOWN
);

while (run)
{
while (SDL_PollEvent(&evt) > 0)
{
if (evt.type == SDL_QUIT)
{
run = 0;
}
else if (evt.type == SDL_KEYDOWN)
{
if (ftoggle)
{
SDL_SetWindowFullscreen(window, 0);
SDL_SetWindowSize(window, 800, 480);
}
else
{
SDL_SetWindowSize(window, mode.w, mode.h);

  			/* Just trying to replicate FNA... */
  			SDL_Delay(1);

  			SDL_SetWindowFullscreen(
  				window,
  				SDL_WINDOW_FULLSCREEN_DESKTOP
  			);
  		}
  		ftoggle = !ftoggle;
  	}
  	else if (evt.type == SDL_WINDOWEVENT)
  	{
  		if (evt.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
  		{
  			SDL_Log(
  				"%d SIZE CHANGE %d %d",
  				SDL_GetTicks(),
  				evt.window.data1,
  				evt.window.data2
  			);
  		}
  		else if (evt.window.event == SDL_WINDOWEVENT_RESIZED)
  		{
  			SDL_Log(
  				"%d RESIZE %d %d",
  				SDL_GetTicks(),
  				evt.window.data1,
  				evt.window.data2
  			);
  		}
  	}
  }

}

SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}


On 2018-10-01 16:42:47 +0000, Sam Lantinga wrote:

Patch added, thanks!
https://hg.libsdl.org/SDL/rev/52dddda6fba7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant