From 03dcd94884406f7023dacfae8899dd49aeed5708 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 3 May 2018 11:49:55 +0900 Subject: [PATCH] shareable: Bug fix: Don't mark disposed when the image becomes not shared --- internal/shareable/shareable.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/shareable/shareable.go b/internal/shareable/shareable.go index 51942ec9a..faa470286 100644 --- a/internal/shareable/shareable.go +++ b/internal/shareable/shareable.go @@ -106,7 +106,7 @@ func (i *Image) ensureNotShared() { newImg := restorable.NewImage(w, h, false) newImg.DrawImage(i.backend.restorable, x, y, x+w, y+h, nil, nil, opengl.CompositeModeCopy, graphics.FilterNearest) - i.dispose() + i.dispose(false) i.backend = &backend{ restorable: newImg, } @@ -195,12 +195,14 @@ func (i *Image) At(x, y int) (color.Color, error) { func (i *Image) Dispose() { backendsM.Lock() defer backendsM.Unlock() - i.dispose() + i.dispose(true) } -func (i *Image) dispose() { +func (i *Image) dispose(markDisposed bool) { defer func() { - i.disposed = true + if markDisposed { + i.disposed = true + } i.backend = nil i.node = nil runtime.SetFinalizer(i, nil)