internal/restorable: Bug fix: Forbid NewImage before the graphics driver is ready

This commit is contained in:
Hajime Hoshi 2021-09-09 03:58:58 +09:00
parent a3570331dd
commit 8f857daf3e
3 changed files with 10 additions and 2 deletions

View File

@ -141,6 +141,10 @@ func ensureEmptyImage() *Image {
//
// Note that Dispose is not called automatically.
func NewImage(width, height int) *Image {
if !graphicsDriverInitialized {
panic("restorable: graphics driver must be ready at NewImage but not")
}
i := &Image{
image: graphicscommand.NewImage(width, height),
width: width,

View File

@ -281,8 +281,11 @@ func (i *images) restore() error {
return nil
}
var graphicsDriverInitialized bool
// InitializeGraphicsDriverState initializes the graphics driver state.
func InitializeGraphicsDriverState() error {
graphicsDriverInitialized = true
return graphicscommand.InitializeGraphicsDriverState()
}

View File

@ -25,9 +25,10 @@ import (
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
)
var emptyImage = NewImage(3, 3)
func clearImage(img *Image, w, h int) {
emptyImage := NewImage(3, 3)
defer emptyImage.Dispose()
dx0 := float32(0)
dy0 := float32(0)
dx1 := float32(w)