-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Windows: SDL reports incorrect height when window height is 0 #9796
Milestone
Comments
Can you post a minimal repro example and steps? Thanks! |
sdl-window-resize.mp4At the time of posting this I realized I used SDL_GetWindowSizeInPixels in the code below so please let me know if I should provide samples using SDL_GetWindowSize. #include <SDL3/SDL.h>
#include <cstdio>
#include <windows.h>
void PrintSize(SDL_Window* window, HWND hwnd)
{
int width = 0;
int height = 0;
SDL_GetWindowSizeInPixels(window, &width, &height);
printf("SDL [%i, %i] ", width, height);
RECT clientRect;
GetClientRect(hwnd, &clientRect);
printf("Windows [%li, %li]\n", clientRect.right - clientRect.left, clientRect.bottom - clientRect.top);
}
int main(int argc, char** argv)
{
SDL_Init(SDL_INIT_VIDEO);
const int initialWidth = 700;
const int initialHeight = 300;
SDL_Window* window = SDL_CreateWindow
(
"Window size test",
initialWidth,
initialHeight,
SDL_WINDOW_RESIZABLE
);
const HWND hwnd = (HWND)SDL_GetProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, NULL);
SDL_Renderer* renderer = SDL_CreateRenderer(window, nullptr, SDL_RENDERER_PRESENTVSYNC);
SDL_SetRenderDrawColor(renderer, 255, 165, 0, 255);
int minWidth = -1;
int minHeight = -1;
SDL_GetWindowMinimumSize(window, &minWidth, &minHeight);
printf("Min window size [%i, %i]\n", minWidth, minHeight);
bool printOnResize = true;
bool open = true;
while(open)
{
SDL_Event e;
while(SDL_PollEvent(&e))
{
if(e.type == SDL_EVENT_KEY_UP && e.key.keysym.sym == SDLK_1)
{
SDL_SetWindowSize(window, initialWidth, 1);
}
else if(e.type == SDL_EVENT_KEY_UP && e.key.keysym.sym == SDLK_2)
{
printOnResize = false;
}
else if(e.type == SDL_EVENT_WINDOW_RESIZED && printOnResize)
{
PrintSize(window, hwnd);
}
else if(e.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED)
{
open = false;
}
}
if(printOnResize == false)
PrintSize(window, hwnd);
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return (0);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Both SDL_GetWindowSize and SDL_GetWindowSizeInPixels report incorrect values when that happens which I believe to be caused by the fix to the previous issue.
I noticed this when following a Vulkan tutorial I attempted to skip rendering if the window had either width or height of 0 but since the functions reported the last known values rather than the "empty size" the check never succeeded. The Vulkan API reported correct dimensions for the VkSurfaceKHR (width 0, height 0). That later caused the validation layers to report an error when creating framebuffers of that size.
I checked the miminum window size using SDL_GetWindowMinimumSize which reported width 0, height 0.
Originally posted by @GitAxeon in #7419 (comment)
The text was updated successfully, but these errors were encountered: