mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
ebiten: recommend errors.Is instead of comparing the returned value directly
Closes #2152
This commit is contained in:
parent
ac18f69f9c
commit
ca8c36499d
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
2
internal/processtest/testdata/issue1753.go
vendored
2
internal/processtest/testdata/issue1753.go
vendored
@ -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)
|
||||
}
|
||||
}
|
||||
|
2
internal/processtest/testdata/issue2079.go
vendored
2
internal/processtest/testdata/issue2079.go
vendored
@ -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)
|
||||
}
|
||||
}
|
||||
|
2
internal/processtest/testdata/issue2089.go
vendored
2
internal/processtest/testdata/issue2089.go
vendored
@ -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)
|
||||
}
|
||||
}
|
||||
|
2
internal/processtest/testdata/issue2129.go
vendored
2
internal/processtest/testdata/issue2129.go
vendored
@ -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)
|
||||
}
|
||||
}
|
||||
|
2
internal/processtest/testdata/issue2154_1.go
vendored
2
internal/processtest/testdata/issue2154_1.go
vendored
@ -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)
|
||||
}
|
||||
}
|
||||
|
2
internal/processtest/testdata/issue2154_2.go
vendored
2
internal/processtest/testdata/issue2154_2.go
vendored
@ -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)
|
||||
}
|
||||
}
|
||||
|
2
internal/processtest/testdata/issue2162.go
vendored
2
internal/processtest/testdata/issue2162.go
vendored
@ -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)
|
||||
}
|
||||
}
|
||||
|
2
internal/processtest/testdata/issue2182.go
vendored
2
internal/processtest/testdata/issue2182.go
vendored
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
6
run.go
@ -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.
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user