mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +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.
|
// Note that Dispose is not called automatically.
|
||||||
func NewImage(width, height int) *Image {
|
func NewImage(width, height int) *Image {
|
||||||
|
if !graphicsDriverInitialized {
|
||||||
|
panic("restorable: graphics driver must be ready at NewImage but not")
|
||||||
|
}
|
||||||
|
|
||||||
i := &Image{
|
i := &Image{
|
||||||
image: graphicscommand.NewImage(width, height),
|
image: graphicscommand.NewImage(width, height),
|
||||||
width: width,
|
width: width,
|
||||||
|
@ -281,8 +281,11 @@ func (i *images) restore() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var graphicsDriverInitialized bool
|
||||||
|
|
||||||
// InitializeGraphicsDriverState initializes the graphics driver state.
|
// InitializeGraphicsDriverState initializes the graphics driver state.
|
||||||
func InitializeGraphicsDriverState() error {
|
func InitializeGraphicsDriverState() error {
|
||||||
|
graphicsDriverInitialized = true
|
||||||
return graphicscommand.InitializeGraphicsDriverState()
|
return graphicscommand.InitializeGraphicsDriverState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +25,10 @@ import (
|
|||||||
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
etesting "github.com/hajimehoshi/ebiten/v2/internal/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var emptyImage = NewImage(3, 3)
|
|
||||||
|
|
||||||
func clearImage(img *Image, w, h int) {
|
func clearImage(img *Image, w, h int) {
|
||||||
|
emptyImage := NewImage(3, 3)
|
||||||
|
defer emptyImage.Dispose()
|
||||||
|
|
||||||
dx0 := float32(0)
|
dx0 := float32(0)
|
||||||
dy0 := float32(0)
|
dy0 := float32(0)
|
||||||
dx1 := float32(w)
|
dx1 := float32(w)
|
||||||
|
Loading…
Reference in New Issue
Block a user