--- a/test/snake/snake.c Wed Jul 30 00:12:13 2025 +0200 +++ b/test/snake/snake.c Thu Jul 31 20:40:48 2025 +0200 @@ -231,16 +231,22 @@ static asc_rect update_viewport_for_window_resize(asc_vec2u window_size) { - // TODO: special case: window is SO small that nothing would be rendered - - // remove margins + // margins const unsigned margin = 10; - window_size.width -= 2*margin; - window_size.height -= 2*margin; + + // space for score, power-ups, etc. + const unsigned left_area = (unsigned) (asc_active_window->ui_scale*200); - // remove space for score, power-ups, etc. - const unsigned left_area = (unsigned) (asc_active_window->ui_scale*200); - window_size.width -= left_area; + // calculate how many pixels need to be removed from width and height + const unsigned rw = 2*margin + left_area; + const unsigned rh = 2*margin; + + // check if there is still a viewport left and chicken out when not + if (window_size.width < rw || window_size.height < rh) { + return ASC_RECT(0, 0, 0, 0); + } + window_size.width -= rw; + window_size.height -= rh; // Compute scaling and offsets unsigned viewport_size, offset_x = 0, offset_y = 0;