From a91009edf73e37b3c4f9ae37e810fcb7b466e277 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 19 Sep 2022 19:20:32 -0500 Subject: grid: protect calls to cell.Content Many panics occur from calling Draw on a nil widget, stemming from the grid ui element. Protect the calls to Draw from within grid to prevent this method of panic. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- lib/ui/grid.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/ui') diff --git a/lib/ui/grid.go b/lib/ui/grid.go index 04a6dc42..fe1d03e8 100644 --- a/lib/ui/grid.go +++ b/lib/ui/grid.go @@ -134,7 +134,9 @@ func (grid *Grid) Draw(ctx *Context) { continue } subctx := ctx.Subcontext(x, y, width, height) - cell.Content.Draw(subctx) + if cell.Content != nil { + cell.Content.Draw(subctx) + } } } @@ -230,7 +232,9 @@ func (grid *Grid) Invalidate() { grid.invalidateLayout() grid.mutex.RLock() for _, cell := range grid.cells { - cell.Content.Invalidate() + if cell.Content != nil { + cell.Content.Invalidate() + } } grid.mutex.RUnlock() } -- cgit