ebiten: recommend errors.Is instead of comparing the returned value directly

Closes #2152
This commit is contained in:
Hajime Hoshi 2022-07-24 23:15:47 +09:00
parent ac18f69f9c
commit ca8c36499d
15 changed files with 18 additions and 16 deletions

View File

@ -127,7 +127,7 @@ func main() {
ebiten.SetFullscreen(true)
ebiten.SetWindowTitle("Fullscreen (Ebiten Demo)")
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
log.Fatal(err)
}
}

View File

@ -340,7 +340,7 @@ func (g *game) Layout(outw, outh int) (int, int) {
func main() {
g := &game{}
if err := ebiten.RunGame(g); err != regularTermination {
if err := ebiten.RunGame(g); err != nil && !errors.Is(err, regularTermination) {
log.Fatal(err)
}
if err := outputKeyRectsGo(g.rects); err != nil {

View File

@ -202,7 +202,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() {
ebiten.SetFullscreen(true)
ebiten.SetWindowTitle("Sprites HD (Ebiten Demo)")
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
log.Fatal(err)
}
}

View File

@ -62,7 +62,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() {
ebiten.SetWindowClosingHandled(true)
ebiten.SetWindowTitle("Window Closing (Ebiten Demo)")
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
log.Fatal(err)
}
}

View File

@ -73,7 +73,7 @@ func TestMain(m *testing.M) {
m: m,
endCh: endCh,
}
if err := ebiten.RunGame(g); err != nil && err != regularTermination {
if err := ebiten.RunGame(g); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}

View File

@ -108,7 +108,7 @@ func (g *Game) Layout(width, height int) (int, int) {
}
func main() {
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}
}

View File

@ -62,7 +62,7 @@ func (g *Game) Layout(width, height int) (int, int) {
}
func main() {
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}
}

View File

@ -72,7 +72,7 @@ func (g *Game) Layout(width, height int) (int, int) {
}
func main() {
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}
}

View File

@ -64,7 +64,7 @@ func (g *Game) Layout(width, height int) (int, int) {
}
func main() {
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}
}

View File

@ -115,7 +115,7 @@ func (g *Game) Layout(width, height int) (int, int) {
}
func main() {
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}
}

View File

@ -86,7 +86,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() {
ebiten.SetWindowTitle("Test")
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}
}

View File

@ -59,7 +59,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() {
// Run a game loop at least for one frame to ensure the shader disposed.
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}
}

View File

@ -87,7 +87,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() {
ebiten.SetWindowTitle("Test")
if err := ebiten.RunGame(&Game{}); err != nil && err != regularTermination {
if err := ebiten.RunGame(&Game{}); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}
}

View File

@ -46,7 +46,7 @@ func MainWithRunLoop(m *testing.M) {
g := &game{
m: m,
}
if err := ebiten.RunGame(g); err != nil && err != regularTermination {
if err := ebiten.RunGame(g); err != nil && !errors.Is(err, regularTermination) {
panic(err)
}
os.Exit(g.code)

6
run.go
View File

@ -183,8 +183,10 @@ func (i *imageDumperGame) Layout(outsideWidth, outsideHeight int) (screenWidth,
// TPS (ticks per second) is 60 by default.
// This is not related to framerate (display's refresh rate).
//
// RunGame returns error when 1) error happens in the underlying graphics driver, 2) audio error happens or
// 3) f returns error. In the case of 3), RunGame returns the same error.
// RunGame returns error when 1) an error happens in the underlying graphics driver, 2) an audio error happens
// or 3) f returns an error. In the case of 3), RunGame returns the same error so far, but it is recommended to
// use errors.Is when you check the returned error is the error you want, rather than comparing the values
// with == or != directly.
//
// The size unit is device-independent pixel.
//