graphice: Dispose old images before restoring

This commit is contained in:
Hajime Hoshi 2016-06-12 20:57:02 +09:00
parent 870ce85615
commit d99bfaf034
2 changed files with 14 additions and 3 deletions

View File

@ -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

View File

@ -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?