From d99bfaf034b347db8d25682fa26c5043da7aab83 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 12 Jun 2016 20:57:02 +0900 Subject: [PATCH] graphice: Dispose old images before restoring --- graphicscontext.go | 2 ++ image.go | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/graphicscontext.go b/graphicscontext.go index 95ff1ea1f..d5242b9c0 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -105,6 +105,8 @@ func (c *graphicsContext) flush() error { } func (c *graphicsContext) Resume() error { + imageM.Lock() + defer imageM.Unlock() ui.GLContext().Resume() if err := graphics.Initialize(ui.GLContext()); err != nil { return err diff --git a/image.go b/image.go index 81050c7a8..c78ab682b 100644 --- a/image.go +++ b/image.go @@ -77,6 +77,17 @@ func (i *images) savePixels(context *opengl.Context, exceptions map[*imageImpl]s func (i *images) restorePixels(context *opengl.Context) error { i.m.Lock() defer i.m.Unlock() + for img := range i.images { + if img.defaultFramebuffer { + continue + } + if img.isDisposed() { + continue + } + if err := img.image.Dispose(); err != nil { + return err + } + } for img := range i.images { if err := img.restorePixels(context); err != nil { return err @@ -274,8 +285,6 @@ func (i *imageImpl) savePixels(context *opengl.Context) error { } func (i *imageImpl) restorePixels(context *opengl.Context) error { - imageM.Lock() - defer imageM.Unlock() if i.defaultFramebuffer { return nil } @@ -332,7 +341,6 @@ func (i *imageImpl) ReplacePixels(p []uint8) error { } imageM.Lock() defer imageM.Unlock() - // TODO: Copy p? if i.pixels == nil { i.pixels = make([]uint8, len(p)) } @@ -410,6 +418,7 @@ func NewImageFromImage(source image.Image, filter Filter) (*Image, error) { draw.Draw(newImg, newImg.Bounds(), origImg, origImg.Bounds().Min, draw.Src) rgbaImg = newImg } + // TODO: Set pixels here? img.image, err = graphics.NewImageFromImage(rgbaImg, glFilter(ui.GLContext(), filter)) if err != nil { // TODO: texture should be removed here?