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 {
|
for _, f := range delayedCommands {
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
|
delayedCommands = nil
|
||||||
delayedCommandsFlushed = 1
|
delayedCommandsFlushed = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,12 @@ package buffered_test
|
|||||||
import (
|
import (
|
||||||
"image/color"
|
"image/color"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/buffered"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mainCh = make(chan func())
|
var mainCh = make(chan func())
|
||||||
@ -303,3 +306,19 @@ func TestWritePixelsAndModifyBeforeMain(t *testing.T) {
|
|||||||
t.Errorf("got: %v, want: %v", got, want)
|
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