Return an error if trying to set a window minimum size larger than the maximum size, or vice versa
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c
index 0cb838c..a7ffef4 100644
--- a/src/video/SDL_video.c
+++ b/src/video/SDL_video.c
@@ -1934,30 +1934,6 @@ SDL_GetWindowSize(SDL_Window * window, int *w, int *h)
}
}
-void
-SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
-{
- CHECK_WINDOW_MAGIC(window,);
- if (min_w <= 0) {
- SDL_InvalidParamError("min_w");
- return;
- }
- if (min_h <= 0) {
- SDL_InvalidParamError("min_h");
- return;
- }
-
- if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
- window->min_w = min_w;
- window->min_h = min_h;
- if (_this->SetWindowMinimumSize) {
- _this->SetWindowMinimumSize(_this, window);
- }
- /* Ensure that window is not smaller than minimal size */
- SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
- }
-}
-
int
SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom, int *right)
{
@@ -1981,6 +1957,36 @@ SDL_GetWindowBordersSize(SDL_Window * window, int *top, int *left, int *bottom,
}
void
+SDL_SetWindowMinimumSize(SDL_Window * window, int min_w, int min_h)
+{
+ CHECK_WINDOW_MAGIC(window,);
+ if (min_w <= 0) {
+ SDL_InvalidParamError("min_w");
+ return;
+ }
+ if (min_h <= 0) {
+ SDL_InvalidParamError("min_h");
+ return;
+ }
+
+ if (min_w >= window->max_w || min_h >= window->max_h) {
+ SDL_SetError("SDL_SetWindowMinimumSize(): Tried to set minimum size larger than maximum size");
+ return;
+ }
+
+ window->min_w = min_w;
+ window->min_h = min_h;
+
+ if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
+ if (_this->SetWindowMinimumSize) {
+ _this->SetWindowMinimumSize(_this, window);
+ }
+ /* Ensure that window is not smaller than minimal size */
+ SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h));
+ }
+}
+
+void
SDL_GetWindowMinimumSize(SDL_Window * window, int *min_w, int *min_h)
{
CHECK_WINDOW_MAGIC(window,);
@@ -2005,9 +2011,15 @@ SDL_SetWindowMaximumSize(SDL_Window * window, int max_w, int max_h)
return;
}
+ if (max_w <= window->min_w || max_h <= window->min_h) {
+ SDL_SetError("SDL_SetWindowMaximumSize(): Tried to set maximum size smaller than minimum size");
+ return;
+ }
+
+ window->max_w = max_w;
+ window->max_h = max_h;
+
if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
- window->max_w = max_w;
- window->max_h = max_h;
if (_this->SetWindowMaximumSize) {
_this->SetWindowMaximumSize(_this, window);
}