From 04d8a654d8d95a59fa04df9833deab8c6ea50b80 Mon Sep 17 00:00:00 2001
From: Frank Praznik <[EMAIL REDACTED]>
Date: Thu, 7 May 2026 12:27:06 -0400
Subject: [PATCH] wayland: Ensure the viewport size is always non-zero
A viewport size of zero is a protocol error, so guard against it when adjusting the aspect ratio.
---
src/video/wayland/SDL_waylandwindow.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c
index c4385b31c679e..10d4524fa228d 100644
--- a/src/video/wayland/SDL_waylandwindow.c
+++ b/src/video/wayland/SDL_waylandwindow.c
@@ -397,26 +397,26 @@ static void ConfigureWindowGeometry(SDL_Window *window)
if (data->viewport && data->waylandData->subcompositor && !data->is_fullscreen) {
if (window->min_w) {
- window_width = viewport_width = SDL_max(viewport_width, window->min_w);
+ viewport_width = SDL_max(viewport_width, window->min_w);
}
if (window->min_h) {
- window_height = viewport_height = SDL_max(viewport_height, window->min_h);
+ viewport_height = SDL_max(viewport_height, window->min_h);
}
if (window->max_w) {
- window_width = viewport_width = SDL_min(viewport_width, window->max_w);
+ viewport_width = SDL_min(viewport_width, window->max_w);
}
if (window->max_h) {
- window_height = viewport_height = SDL_min(viewport_height, window->max_h);
+ viewport_height = SDL_min(viewport_height, window->max_h);
}
float aspect = (float)viewport_width / (float)viewport_height;
if (window->min_aspect != 0.f && aspect < window->min_aspect) {
- viewport_height = SDL_lroundf((float)viewport_width / window->min_aspect);
+ viewport_height = SDL_max(SDL_lroundf((float)viewport_width / window->min_aspect), 1);
} else if (window->max_aspect != 0.f && aspect > window->max_aspect) {
- viewport_width = SDL_lroundf((float)viewport_height * window->max_aspect);
+ viewport_width = SDL_max(SDL_lroundf((float)viewport_height * window->max_aspect), 1);
}
- // At this point, the viewport matches the window dimensions, but the viewport might be clamped to window dimensions beyond here.
+ // At this point, the viewport matches the virtual window dimensions, but the viewport might be clamped to the output window dimensions beyond here.
window_width = viewport_width;
window_height = viewport_height;
@@ -446,6 +446,9 @@ static void ConfigureWindowGeometry(SDL_Window *window)
}
}
}
+
+ viewport_width = SDL_max(viewport_width, 1);
+ viewport_height = SDL_max(viewport_height, 1);
} else {
window_width = viewport_width;
window_height = viewport_height;