From da553974205e0a01f63d5e2d4e713a178c2b0cc3 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 8 Mar 2023 16:32:41 +0900 Subject: [PATCH] internal/restorable: remove empty regions at appendRegionsForDrawTriangles --- internal/restorable/image.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 6c03628ca..90393fddb 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -690,6 +690,7 @@ func (i *Image) appendRegionsForDrawTriangles(regions []image.Rectangle) []image continue } + // Replace duplicated regions with empty regions. for i, rr := range regions[origIndex:] { if rr.Empty() { continue @@ -702,7 +703,17 @@ func (i *Image) appendRegionsForDrawTriangles(regions []image.Rectangle) []image regions = append(regions, r) } - return regions + // Remove empty regions. + n := origIndex + for _, r := range regions[origIndex:] { + if r.Empty() { + continue + } + regions[n] = r + n++ + } + + return regions[:n] } func regionToRectangle(region graphicsdriver.Region) image.Rectangle {