mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
shareable: Set finalizers
This commit is contained in:
parent
a2d6ae7eee
commit
c411ca492f
@ -17,6 +17,7 @@ package shareable
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||||
@ -116,6 +117,7 @@ func (s *Image) Dispose() {
|
|||||||
defer func() {
|
defer func() {
|
||||||
s.backend = nil
|
s.backend = nil
|
||||||
s.node = nil
|
s.node = nil
|
||||||
|
runtime.SetFinalizer(s, nil)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if s.node == nil {
|
if s.node == nil {
|
||||||
@ -180,26 +182,32 @@ func NewImage(width, height int) *Image {
|
|||||||
if n == nil {
|
if n == nil {
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
return &Image{
|
i := &Image{
|
||||||
backend: s,
|
backend: s,
|
||||||
node: n,
|
node: n,
|
||||||
}
|
}
|
||||||
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewVolatileImage(width, height int) *Image {
|
func NewVolatileImage(width, height int) *Image {
|
||||||
r := restorable.NewImage(width, height, true)
|
r := restorable.NewImage(width, height, true)
|
||||||
return &Image{
|
i := &Image{
|
||||||
backend: &backend{
|
backend: &backend{
|
||||||
restorable: r,
|
restorable: r,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewScreenFramebufferImage(width, height int) *Image {
|
func NewScreenFramebufferImage(width, height int) *Image {
|
||||||
r := restorable.NewScreenFramebufferImage(width, height)
|
r := restorable.NewScreenFramebufferImage(width, height)
|
||||||
return &Image{
|
i := &Image{
|
||||||
backend: &backend{
|
backend: &backend{
|
||||||
restorable: r,
|
restorable: r,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
|
return i
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user