renderer: don't assume non-zero sized grid
Fixes #8243 This adds a check for a zero-sized grid in cursor-related functions. As an alternate approach, I did look into simply skipping a bunch of work on zero-sized grids, but that looked like a scarier change to make now. That may be the better long-term solution but this was an easily unit testable, focused fix on the crash to start.pull/8246/head
parent
4e26bb65ae
commit
9ccc02b131
|
|
@ -141,7 +141,12 @@ pub const Contents = struct {
|
|||
}
|
||||
|
||||
/// Set the cursor value. If the value is null then the cursor is hidden.
|
||||
pub fn setCursor(self: *Contents, v: ?shaderpkg.CellText, cursor_style: ?renderer.CursorStyle) void {
|
||||
pub fn setCursor(
|
||||
self: *Contents,
|
||||
v: ?shaderpkg.CellText,
|
||||
cursor_style: ?renderer.CursorStyle,
|
||||
) void {
|
||||
if (self.size.rows == 0) return;
|
||||
self.fg_rows.lists[0].clearRetainingCapacity();
|
||||
self.fg_rows.lists[self.size.rows + 1].clearRetainingCapacity();
|
||||
|
||||
|
|
@ -158,6 +163,7 @@ pub const Contents = struct {
|
|||
|
||||
/// Returns the current cursor glyph if present, checking both cursor lists.
|
||||
pub fn getCursorGlyph(self: *Contents) ?shaderpkg.CellText {
|
||||
if (self.size.rows == 0) return null;
|
||||
if (self.fg_rows.lists[0].items.len > 0) {
|
||||
return self.fg_rows.lists[0].items[0];
|
||||
}
|
||||
|
|
@ -469,3 +475,14 @@ test "Contents clear last added content" {
|
|||
// Fg row index is +1 because of cursor list at start
|
||||
try testing.expectEqual(fg_cell_1, c.fg_rows.lists[2].items[0]);
|
||||
}
|
||||
|
||||
test "Contents with zero-sized screen" {
|
||||
const testing = std.testing;
|
||||
const alloc = testing.allocator;
|
||||
|
||||
var c: Contents = .{};
|
||||
defer c.deinit(alloc);
|
||||
|
||||
c.setCursor(null, null);
|
||||
try testing.expect(c.getCursorGlyph() == null);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue