internal/buffered: bug fix: images created in init() were not GCed

Closes #2805
This commit is contained in:
Hajime Hoshi 2023-10-10 00:31:42 +09:00
parent a27e3b6f34
commit 531f463a19
2 changed files with 20 additions and 0 deletions

View File

@ -44,6 +44,7 @@ func flushDelayedCommandsSlow() {
for _, f := range delayedCommands {
f()
}
delayedCommands = nil
delayedCommandsFlushed = 1
}
}

View File

@ -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")
}
}