graphics: Add image.disposed

This commit is contained in:
Hajime Hoshi 2016-05-08 03:42:22 +09:00
parent 61ed13e322
commit b8a062e813
2 changed files with 3 additions and 5 deletions

View File

@ -32,6 +32,7 @@ var imageM sync.Mutex
type Image struct { type Image struct {
framebuffer *graphics.Framebuffer framebuffer *graphics.Framebuffer
texture *graphics.Texture texture *graphics.Texture
disposed bool
pixels []uint8 pixels []uint8
width int width int
height int height int
@ -203,12 +204,8 @@ func (i *Image) Dispose() error {
return c.Exec() return c.Exec()
} }
// FIXME: This returns true when image is temporal state!
func (i *Image) isDisposed() bool { func (i *Image) isDisposed() bool {
// i.texture can be nil even when the image is not disposed, return i.disposed
// so we need to check if both are nil.
// See graphicsContext.setSize function.
return i.texture == nil && i.framebuffer == nil
} }
// ReplacePixels replaces the pixels of the image with p. // ReplacePixels replaces the pixels of the image with p.

View File

@ -109,6 +109,7 @@ func (c *disposeCommand) Exec() error {
} }
c.image.texture = nil c.image.texture = nil
} }
c.image.disposed = true
c.image.pixels = nil c.image.pixels = nil
runtime.SetFinalizer(c.image, nil) runtime.SetFinalizer(c.image, nil)
return nil return nil