Skip to content

Commit 7172d7d

Browse files
committed
rg_gui: Fixed a crash when drawing text entirely offscreen
1 parent c87802a commit 7172d7d

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

components/retro-go/rg_gui.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,14 @@ rg_rect_t rg_gui_draw_text(int x_pos, int y_pos, int width, const char *text, //
379379
x_pos = get_horizontal_position(x_pos, width);
380380
y_pos = get_vertical_position(y_pos, line_height);
381381

382-
if (x_pos + width > gui.screen_width || y_pos + line_height > gui.screen_height)
382+
if (x_pos >= gui.screen_width || y_pos >= gui.screen_height)
383383
{
384-
RG_LOGD("Texbox (pos: %dx%d, size: %dx%d) will be truncated!", width, line_height, x_pos, y_pos);
384+
RG_LOGD("Texbox (x: %d, y:%d) is entirely outside the screen!", x_pos, y_pos);
385+
return (rg_rect_t){x_pos, y_pos, 0, 0};
386+
}
387+
else if (x_pos + width > gui.screen_width || y_pos + line_height > gui.screen_height)
388+
{
389+
RG_LOGD("Texbox (pos: %dx%d, size: %dx%d) will be truncated!", x_pos, y_pos, width, line_height);
385390
// return;
386391
}
387392

0 commit comments

Comments
 (0)