diff --git a/internal/buffered/command.go b/internal/buffered/command.go index 881d5e2a1..741873870 100644 --- a/internal/buffered/command.go +++ b/internal/buffered/command.go @@ -44,6 +44,7 @@ func flushDelayedCommandsSlow() { for _, f := range delayedCommands { f() } + delayedCommands = nil delayedCommandsFlushed = 1 } } diff --git a/internal/buffered/image_test.go b/internal/buffered/image_test.go index c07388369..ce7d73882 100644 --- a/internal/buffered/image_test.go +++ b/internal/buffered/image_test.go @@ -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") + } +}