From becada4afc250ff3b4435fde5030ea4e422d37c1 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 6 Sep 2024 14:14:02 +0900 Subject: [PATCH] Revert "internal/restorable: refactoring" This reverts commit 81e110461362ee490c26ddf18f41d27446840870. Updates #3083 --- internal/restorable/image.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/restorable/image.go b/internal/restorable/image.go index d77eb9fe2..0ce4d25c1 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -88,10 +88,7 @@ func clearImage(i *graphicscommand.Image, region image.Rectangle) { // ClearPixels clears the specified region by WritePixels. func (i *Image) ClearPixels(region image.Rectangle) { - if region.Dx() <= 0 || region.Dy() <= 0 { - panic("restorable: width/height must be positive") - } - clearImage(i.Image, region.Intersect(image.Rect(0, 0, i.width, i.height))) + i.WritePixels(nil, region) } // WritePixels replaces the image pixels with the given pixels slice. @@ -106,7 +103,11 @@ func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangl panic(fmt.Sprintf("restorable: out of range %v", region)) } - i.Image.WritePixels(pixels, region) + if pixels != nil { + i.Image.WritePixels(pixels, region) + } else { + clearImage(i.Image, region) + } } // DrawTriangles draws triangles with the given image.