From ea440f5b17c93f5372f83399f993e9e4ffa9e6d7 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 12 Jun 2016 21:19:54 +0900 Subject: [PATCH] graphics: Bug fix: Don't touch interface after locking --- image.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/image.go b/image.go index c78ab682b..6a20691e0 100644 --- a/image.go +++ b/image.go @@ -399,32 +399,33 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) { size := source.Bounds().Size() w, h := size.X, size.Y // TODO: Return error when the image is too big! - img := &imageImpl{ - width: w, - height: h, - filter: filter, - } - imageM.Lock() - defer imageM.Unlock() - eimg, err := theImages.add(img) - if err != nil { - return nil, err - } // Don't lock while manipulating an image.Image interface. rgbaImg, ok := source.(*image.RGBA) - if !ok { + if !ok || source.Bounds().Min != image.ZP { origImg := source newImg := image.NewRGBA(origImg.Bounds()) draw.Draw(newImg, newImg.Bounds(), origImg, origImg.Bounds().Min, draw.Src) rgbaImg = newImg } // TODO: Set pixels here? + imageM.Lock() + defer imageM.Unlock() + img := &imageImpl{ + width: w, + height: h, + filter: filter, + } + var err error img.image, err = graphics.NewImageFromImage(rgbaImg, glFilter(ui.GLContext(), filter)) if err != nil { // TODO: texture should be removed here? return nil, err } runtime.SetFinalizer(img, (*imageImpl).Dispose) + eimg, err := theImages.add(img) + if err != nil { + return nil, err + } return eimg, nil }