fix (renderer): fixed possible PF when printing \n

This commit is contained in:
antifallobst 2023-05-02 00:40:40 +02:00
parent ddc47b3ea3
commit 0c084d00c0
1 changed files with 9 additions and 8 deletions

View File

@ -99,6 +99,15 @@ position_T graphics_buffer_draw_string(graphics_buffer_T* graphics_buffer, uint3
position_T pos = (position_T){x, y}; position_T pos = (position_T){x, y};
uint64_t strlen = string_length(string); uint64_t strlen = string_length(string);
for (int i = 0; i < strlen; i++) { for (int i = 0; i < strlen; i++) {
if (pos.x + g_renderer.font.width >= graphics_buffer->width) {
pos.x = 0;
pos.y += g_renderer.font.height;
}
if (pos.y + g_renderer.font.height >= graphics_buffer->height) {
pos.y -= g_renderer.font.height;
graphics_buffer_shift_up(graphics_buffer, g_renderer.font.height);
}
switch (string[i]) { switch (string[i]) {
case '\n': { case '\n': {
pos.x = 0; pos.x = 0;
@ -122,14 +131,6 @@ position_T graphics_buffer_draw_string(graphics_buffer_T* graphics_buffer, uint3
} }
default: { default: {
if (pos.x + g_renderer.font.width >= graphics_buffer->width) {
pos.x = 0;
pos.y += g_renderer.font.height;
}
if (pos.y + g_renderer.font.height >= graphics_buffer->height) {
pos.y -= g_renderer.font.height;
graphics_buffer_shift_up(graphics_buffer, g_renderer.font.height);
}
graphics_buffer_draw_char(graphics_buffer, pos.x, pos.y, color, string[i]); graphics_buffer_draw_char(graphics_buffer, pos.x, pos.y, color, string[i]);
pos.x += g_renderer.font.width; pos.x += g_renderer.font.width;
break; break;