Resize on windows scales input weirdly on first present.
Compile the following code with SDL3:
#include <SDL3/SDL.h>
#include "stdlib.h"
#include "stdio.h"
#define SHOW_SDL_BUG_WORKAROUND 0
void show_sld_bug_render_rect(SDL_Window*w, SDL_Renderer* r) {
SDL_RenderClear(r);
#if SHOW_SDL_BUG_WORKAROUND
SDL_RenderPresent(r);
#endif
SDL_Rect total_size{};
SDL_GetWindowSize(w, &total_size.w, &total_size.h);
SDL_FRect left{0.f, 0.f, (float)total_size.w / 2, (float)total_size.h};
SDL_FRect right{left.w, 0.f, left.w, left.h};
SDL_SetRenderDrawColor(r, 255, 0, 0, 255);
SDL_RenderFillRect(r, &left);
SDL_SetRenderDrawColor(r, 0, 0, 255, 255);
SDL_RenderFillRect(r, &right);
SDL_RenderPresent(r);
}
void show_sdl_bug_cleanup() {
SDL_QuitSubSystem(SDL_INIT_VIDEO);
SDL_Quit();
}
int main() {
SDL_Init(0);
SDL_InitSubSystem(SDL_INIT_VIDEO);
SDL_Window* w = SDL_CreateWindow("Hello", 500, 500, SDL_WINDOW_RESIZABLE);
if(!w) {
printf("Error: %s\n", SDL_GetError());
return EXIT_FAILURE;
}
SDL_Renderer* r = SDL_GetRenderer(w);
if(!r) {
r = SDL_CreateRenderer(w, nullptr);
}
show_sld_bug_render_rect(w, r);
SDL_Event e;
while(SDL_WaitEvent(&e)) {
switch (e.type) {
case SDL_EVENT_WINDOW_RESIZED:
show_sld_bug_render_rect(w, r);
break;
case SDL_EVENT_QUIT:
show_sdl_bug_cleanup();
return EXIT_SUCCESS;
}
}
show_sdl_bug_cleanup();
return EXIT_FAILURE;
}
and resize the window in width. The rectangles does not scale the way you would expect. Change SHOW_SDL_BUG_WORKAROUND to 1 and things will seem to work again.
Error is seen on commit 615d2dcd5b6352aea50372745a05779e24ff8d31 and 802686699449289109f58b9ec4e6200f061e9dd2 . I have not experienced similar behaviour in SDL2.
System information: OS - Windows 11 Processor: Intel I7 1280P Graphics: Integrated Screen: Laptop screen with 2880x1600 (2x scaling in windows)
Sam bug as #11324 ?
Seems very similar at least. I see it on Windows and the referenced report is Android. I can say that querying the size of the window gives the expected result.
// Robin
On Sun, Nov 3, 2024, 18:29 Anthony @.***> wrote:
Sam bug as #11324 https://github.com/libsdl-org/SDL/issues/11324 ?
— Reply to this email directly, view it on GitHub https://github.com/libsdl-org/SDL/issues/11401#issuecomment-2453504308, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHEBBRVIZXQTG564XOHEKY3Z6ZMOVAVCNFSM6AAAAABRCXEIY6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINJTGUYDIMZQHA . You are receiving this because you authored the thread.Message ID: @.***>
Duplicate of https://github.com/libsdl-org/SDL/issues/11324
There's a workaround mentioned in that bug that may help you.