mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
internal/restorable: Bug fix: Forbid NewImage before the graphics driver is ready
This commit is contained in:
parent
a3570331dd
commit
8f857daf3e
@ -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,
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user