Fixed crash if GetRectDisplayIndex() is called before SDL_VideoInit()
(cherry picked from commit d87048fd5a7dff55c4cb205dd29e527c9cc51225)main
parent
1e2dfdb019
commit
f8c3528c55
|
@ -1105,25 +1105,27 @@ static int GetRectDisplayIndex(int x, int y, int w, int h)
|
||||||
center.x = x + w / 2;
|
center.x = x + w / 2;
|
||||||
center.y = y + h / 2;
|
center.y = y + h / 2;
|
||||||
|
|
||||||
for (i = 0; i < _this->num_displays; ++i) {
|
if (_this) {
|
||||||
SDL_Rect display_rect;
|
for (i = 0; i < _this->num_displays; ++i) {
|
||||||
SDL_GetDisplayBounds(i, &display_rect);
|
SDL_Rect display_rect;
|
||||||
|
SDL_GetDisplayBounds(i, &display_rect);
|
||||||
|
|
||||||
/* Check if the window is fully enclosed */
|
/* Check if the window is fully enclosed */
|
||||||
if (SDL_EnclosePoints(¢er, 1, &display_rect, NULL)) {
|
if (SDL_EnclosePoints(¢er, 1, &display_rect, NULL)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Snap window center to the display rect */
|
/* Snap window center to the display rect */
|
||||||
closest_point_on_display = center;
|
closest_point_on_display = center;
|
||||||
SDL_GetClosestPointOnRect(&display_rect, &closest_point_on_display);
|
SDL_GetClosestPointOnRect(&display_rect, &closest_point_on_display);
|
||||||
|
|
||||||
delta.x = center.x - closest_point_on_display.x;
|
delta.x = center.x - closest_point_on_display.x;
|
||||||
delta.y = center.y - closest_point_on_display.y;
|
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) {
|
if (dist < closest_dist) {
|
||||||
closest = i;
|
closest = i;
|
||||||
closest_dist = dist;
|
closest_dist = dist;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue