diff --git a/graphicscontext.go b/graphicscontext.go index abe55d86f..b734c3169 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -61,10 +61,10 @@ func (c *graphicsContext) postUpdate() error { func (c *graphicsContext) setSize(screenWidth, screenHeight, screenScale int) error { if c.defaultRenderTarget != nil { - c.defaultRenderTarget.dispose() + c.defaultRenderTarget.Dispose() } if c.screen != nil { - c.screen.dispose() + c.screen.Dispose() } var err error diff --git a/image.go b/image.go index a1b56a5cf..6d485ea10 100644 --- a/image.go +++ b/image.go @@ -128,18 +128,26 @@ func (i *Image) At(x, y int) color.Color { return color.RGBA{r, g, b, a} } -func (i *Image) dispose() { +// Dispose disposes the image data. After disposing, the image becomes invalid. +// This is useful to save memory. +func (i *Image) Dispose() { + if i.isDisposed() { + panic("the image is already disposed") + } useGLContext(func(c *opengl.Context) { - if i.framebuffer != nil { - i.framebuffer.Dispose(c) - } - if i.texture != nil { - i.texture.Dispose(c) - } + i.framebuffer.Dispose(c) + i.framebuffer = nil + i.texture.Dispose(c) + i.texture = nil }) i.pixels = nil } +// IsDisposed returns a boolean indicating wheather the image is disposed. +func (i *Image) IsDisposed() bool { + return i.texture == nil +} + // ReplacePixels replaces the pixels of the image with p. // // The given p must represent RGBA pre-multiplied alpha values. len(p) must equal to 4 * (image width) * (image height).