Skip to content

Commit 83e028f

Browse files
committed
Replace Rectf with plain floats to avoid assert()
If request.rect is close to zero in width/height the code might produce an invalid Rectf (left > right, top > bottom) due to float imprecision. Going with plain floats avoids this unnecessary check. Fixes #2167
1 parent 5efa7ed commit 83e028f

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/video/gl/gl_painter.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,12 @@ GLPainter::draw_filled_rect(const FillRectRequest& request)
251251
std::min(request.rect.get_width() / 2.0f,
252252
request.rect.get_height() / 2.0f));
253253

254-
// inner rectangle
255-
const Rectf irect(request.rect.get_left() + radius,
256-
request.rect.get_top() + radius,
257-
request.rect.get_right() - radius,
258-
request.rect.get_bottom() - radius);
254+
// Not using Rectf here as the resulting Rectf might be invalid
255+
// and assert() due to float imprecision
256+
const float inner_rect_left = request.rect.get_left() + radius;
257+
const float inner_rect_top = request.rect.get_top() + radius;
258+
const float inner_rect_right = request.rect.get_right() - radius;
259+
const float inner_rect_bottom = request.rect.get_bottom() - radius;
259260

260261
const int n = 8;
261262
size_t p = 0;
@@ -266,23 +267,23 @@ GLPainter::draw_filled_rect(const FillRectRequest& request)
266267
const float x = sinf(static_cast<float>(i) * math::PI_2 / static_cast<float>(n)) * radius;
267268
const float y = cosf(static_cast<float>(i) * math::PI_2 / static_cast<float>(n)) * radius;
268269

269-
vertices[p++] = irect.get_left() - x;
270-
vertices[p++] = irect.get_top() - y;
270+
vertices[p++] = inner_rect_left - x;
271+
vertices[p++] = inner_rect_top - y;
271272

272-
vertices[p++] = irect.get_right() + x;
273-
vertices[p++] = irect.get_top() - y;
273+
vertices[p++] = inner_rect_right + x;
274+
vertices[p++] = inner_rect_top - y;
274275
}
275276

276277
for (int i = 0; i <= n; ++i)
277278
{
278279
const float x = cosf(static_cast<float>(i) * math::PI_2 / static_cast<float>(n)) * radius;
279280
const float y = sinf(static_cast<float>(i) * math::PI_2 / static_cast<float>(n)) * radius;
280281

281-
vertices[p++] = irect.get_left() - x;
282-
vertices[p++] = irect.get_bottom() + y;
282+
vertices[p++] = inner_rect_left - x;
283+
vertices[p++] = inner_rect_bottom + y;
283284

284-
vertices[p++] = irect.get_right() + x;
285-
vertices[p++] = irect.get_bottom() + y;
285+
vertices[p++] = inner_rect_right + x;
286+
vertices[p++] = inner_rect_bottom + y;
286287
}
287288

288289
context.set_positions(vertices.data(), sizeof(float) * vertices.size());

0 commit comments

Comments
 (0)