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.SetFullscreen(true)
ebiten.SetWindowTitle("Fullscreen (Ebiten Demo)") 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) log.Fatal(err)
} }
} }

View File

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

View File

@ -202,7 +202,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() { func main() {
ebiten.SetFullscreen(true) ebiten.SetFullscreen(true)
ebiten.SetWindowTitle("Sprites HD (Ebiten Demo)") 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) log.Fatal(err)
} }
} }

View File

@ -62,7 +62,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() { func main() {
ebiten.SetWindowClosingHandled(true) ebiten.SetWindowClosingHandled(true)
ebiten.SetWindowTitle("Window Closing (Ebiten Demo)") 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) log.Fatal(err)
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -86,7 +86,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() { func main() {
ebiten.SetWindowTitle("Test") 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) panic(err)
} }
} }

View File

@ -59,7 +59,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() { func main() {
// Run a game loop at least for one frame to ensure the shader disposed. // 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) panic(err)
} }
} }

View File

@ -87,7 +87,7 @@ func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
func main() { func main() {
ebiten.SetWindowTitle("Test") 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) panic(err)
} }
} }

View File

@ -46,7 +46,7 @@ func MainWithRunLoop(m *testing.M) {
g := &game{ g := &game{
m: m, m: m,
} }
if err := ebiten.RunGame(g); err != nil && err != regularTermination { if err := ebiten.RunGame(g); err != nil && !errors.Is(err, regularTermination) {
panic(err) panic(err)
} }
os.Exit(g.code) 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. // TPS (ticks per second) is 60 by default.
// This is not related to framerate (display's refresh rate). // 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 // RunGame returns error when 1) an error happens in the underlying graphics driver, 2) an audio error happens
// 3) f returns error. In the case of 3), RunGame returns the same error. // 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. // The size unit is device-independent pixel.
// //