mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/buffered: bug fix: images created in init() were not GCed
Closes #2805
This commit is contained in:
parent
738f13f73f
commit
cc5174f104
@ -44,6 +44,7 @@ func flushDelayedCommandsSlow() {
|
||||
for _, f := range delayedCommands {
|
||||
f()
|
||||
}
|
||||
delayedCommands = nil
|
||||
delayedCommandsFlushed = 1
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,12 @@ package buffered_test
|
||||
import (
|
||||
"image/color"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/buffered"
|
||||
)
|
||||
|
||||
var mainCh = make(chan func())
|
||||
@ -303,3 +306,19 @@ func TestWritePixelsAndModifyBeforeMain(t *testing.T) {
|
||||
t.Errorf("got: %v, want: %v", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
var isImageGCed bool
|
||||
|
||||
func init() {
|
||||
img := buffered.NewImage(1, 1, atlas.ImageTypeRegular)
|
||||
runtime.SetFinalizer(img, func(*buffered.Image) {
|
||||
isImageGCed = true
|
||||
})
|
||||
}
|
||||
|
||||
func TestGC(t *testing.T) {
|
||||
runtime.GC()
|
||||
if !isImageGCed {
|
||||
t.Error("an image in init() must be GCed but not")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user