SDL
SDL copied to clipboard
RESIZE events differ in behavior between Windows and Linux (not tested on MacOS)
On Windows, the main thread doesn't get resize events until the user stops resizing and lets go of the frame On Linux, the main thread gets constant resize events while the user is resizing the window
SDL2 reproducer
#include <stdio.h>
#define SDL_MAIN_HANDLED
#include "SDL2/SDL.h"
int main()
{
int w = 200;
int h = 200;
if (SDL_InitSubSystem(SDL_INIT_VIDEO))
{
printf("Failed to init video");
return 1;
}
SDL_Window* win = SDL_CreateWindow("test window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, 0);
if (win == NULL)
{
printf("win is NULL");
return -1;
}
SDL_Surface* surf = SDL_GetWindowSurface(win);
if (surf == NULL)
{
printf("surf is NULL");
return -1;
}
SDL_SetWindowResizable(win, SDL_TRUE);
printf("surf->size == %d,%d\n", surf->w, surf->h);
int running = 1;
while (running)
{
SDL_PumpEvents();
SDL_Event event;
while (SDL_PollEvent(&event) > 0)
{
if (event.type == SDL_QUIT)
{
running = 0;
}
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED)
{
printf("Resize event to (%d, %d)\n", event.window.data1, event.window.data2);
surf = SDL_GetWindowSurface(win);
if (surf == NULL)
{
printf("surf is NULL");
return -1;
}
printf("surf->size == %d,%d\n", surf->w, surf->h);
}
}
}
SDL_DestroyWindow(win);
return 0;
}
SDL3 reproducer
#include <stdio.h>
#define SDL_MAIN_HANDLED
#include "SDL3/SDL.h"
int main()
{
int w = 200;
int h = 200;
if (!SDL_InitSubSystem(SDL_INIT_VIDEO))
{
printf("Failed to init video");
return 1;
}
SDL_Window* win = SDL_CreateWindow("test window", w, h, 0);
if (win == NULL)
{
printf("win is NULL");
return -1;
}
SDL_Surface* surf = SDL_GetWindowSurface(win);
if (surf == NULL)
{
printf("surf is NULL");
return -1;
}
SDL_SetWindowResizable(win, 1);
printf("surf->size == %d,%d\n", surf->w, surf->h);
int running = 1;
while (running)
{
SDL_PumpEvents();
SDL_Event event;
while (SDL_PollEvent(&event) > 0)
{
if (event.type == SDL_EVENT_QUIT)
{
running = 0;
}
if (event.type == SDL_EVENT_WINDOW_RESIZED)
{
printf("Resize event to (%d, %d)\n", event.window.data1, event.window.data2);
surf = SDL_GetWindowSurface(win);
if (surf == NULL)
{
printf("surf is NULL");
return -1;
}
printf("surf->size == %d,%d\n", surf->w, surf->h);
}
}
}
SDL_DestroyWindow(win);
return 0;
}