Fixed crash if GetRectDisplayIndex() is called before SDL_VideoInit()

(cherry picked from commit d87048fd5a7dff55c4cb205dd29e527c9cc51225)
This commit is contained in:
Sam Lantinga 2022-11-30 14:37:34 -08:00
parent 45c7d838d4
commit 2879f2aeba

View File

@ -1157,6 +1157,7 @@ GetRectDisplayIndex(int x, int y, int w, int h)
center.x = x + w / 2;
center.y = y + h / 2;
if (_this) {
for (i = 0; i < _this->num_displays; ++i) {
SDL_Rect display_rect;
SDL_GetDisplayBounds(i, &display_rect);
@ -1172,12 +1173,13 @@ GetRectDisplayIndex(int x, int y, int w, int h)
delta.x = center.x - closest_point_on_display.x;
delta.y = center.y - closest_point_on_display.y;
dist = (delta.x*delta.x + delta.y*delta.y);
dist = (delta.x * delta.x + delta.y * delta.y);
if (dist < closest_dist) {
closest = i;
closest_dist = dist;
}
}
}
if (closest < 0) {
SDL_SetError("Couldn't find any displays");