Skip to content

Commit 9bd2a61

Browse files
committed
supervisor: Always allocate at least a 1x1 terminal
Otherwise, out of range writes would occur in tilegrid_set_tile, causing a safe mode reset. ``` Hardware watchpoint 6: -location *stack_alloc->ptr Old value = 24652061 New value = 24641565 0x000444f2 in common_hal_displayio_tilegrid_set_tile (self=0x200002c8 <supervisor_terminal_text_grid>, x=1, y=1, tile_index=0 '\000') at ../../shared-module/displayio/TileGrid.c:236 236 if (!self->partial_change) { (gdb) ```
1 parent 952d9bb commit 9bd2a61

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

supervisor/shared/display.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,14 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
6565
if (width_in_tiles < 80) {
6666
scale = 1;
6767
}
68+
6869
width_in_tiles = (width_px - blinka_bitmap.width * scale) / (grid->tile_width * scale);
70+
if (width_in_tiles < 1) {
71+
width_in_tiles = 1;
72+
}
6973
uint16_t height_in_tiles = height_px / (grid->tile_height * scale);
7074
uint16_t remaining_pixels = height_px % (grid->tile_height * scale);
71-
if (remaining_pixels > 0) {
75+
if (height_in_tiles < 1 || remaining_pixels > 0) {
7276
height_in_tiles += 1;
7377
}
7478

@@ -94,6 +98,8 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) {
9498
}
9599
grid->width_in_tiles = width_in_tiles;
96100
grid->height_in_tiles = height_in_tiles;
101+
assert(width_in_tiles > 0);
102+
assert(height_in_tiles > 0);
97103
grid->pixel_width = width_in_tiles * grid->tile_width;
98104
grid->pixel_height = height_in_tiles * grid->tile_height;
99105
grid->tiles = tiles;

0 commit comments

Comments
 (0)