From 025fd00e6b1e66940135dae015b4961b5004bd6e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 25 Mar 2018 20:39:06 +0900 Subject: [PATCH] restorable: Bug fix: Make the image stale when pixels are partly replaced --- internal/restorable/image.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 9a4908ba5..25f51a122 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -133,21 +133,28 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) { i.image.ReplacePixels(pixels, x, y, width, height) - // Copy the pixels so that this works even p is modified just after ReplacePixels. - if i.basePixels == nil { - if x == 0 && y == 0 && width == w && height == h { + if x == 0 && y == 0 && width == w && height == h { + if i.basePixels == nil { i.basePixels = make([]byte, 4*w*h) - } else { - i.makeStale() - return } + copy(i.basePixels, pixels) + i.drawImageHistory = nil + i.stale = false + return + } + if i.basePixels == nil { + i.makeStale() + return + } + if len(i.drawImageHistory) > 0 { + i.makeStale() + return } idx := 4 * (y*w + x) for j := 0; j < height; j++ { copy(i.basePixels[idx:idx+4*width], pixels[4*j*width:4*(j+1)*width]) idx += 4 * w } - i.drawImageHistory = nil i.stale = false }