diff --git a/ebitenutil/loadimage.go b/ebitenutil/loadimage.go index 793384589..22b41c715 100644 --- a/ebitenutil/loadimage.go +++ b/ebitenutil/loadimage.go @@ -34,7 +34,9 @@ func NewImageFromFile(path string, filter ebiten.Filter) (*ebiten.Image, image.I if err != nil { return nil, nil, err } - defer file.Close() + defer func() { + _ = file.Close() + }() img, _, err := image.Decode(file) if err != nil { return nil, nil, err diff --git a/examples/2048/2048/board.go b/examples/2048/2048/board.go index 1b1bc6469..c52cb3a73 100644 --- a/examples/2048/2048/board.go +++ b/examples/2048/2048/board.go @@ -30,15 +30,17 @@ type Board struct { tasks []task } -func NewBoard(size int) *Board { +func NewBoard(size int) (*Board, error) { b := &Board{ size: size, tiles: map[*Tile]struct{}{}, } for i := 0; i < 2; i++ { - addRandomTile(b.tiles, b.size) + if err := addRandomTile(b.tiles, b.size); err != nil { + return nil, err + } } - return b + return b, nil } func (b *Board) tileAt(x, y int) *Tile { diff --git a/examples/2048/2048/game.go b/examples/2048/2048/game.go index 9236b73e2..b3116a6b5 100644 --- a/examples/2048/2048/game.go +++ b/examples/2048/2048/game.go @@ -37,11 +37,16 @@ type Game struct { boardImage *ebiten.Image } -func NewGame() *Game { - return &Game{ +func NewGame() (*Game, error) { + g := &Game{ input: NewInput(), - board: NewBoard(boardSize), } + var err error + g.board, err = NewBoard(boardSize) + if err != nil { + return nil, err + } + return g, nil } func (g *Game) Update() error { diff --git a/examples/2048/2048/tile.go b/examples/2048/2048/tile.go index a832602dd..944ea9c7c 100644 --- a/examples/2048/2048/tile.go +++ b/examples/2048/2048/tile.go @@ -346,6 +346,8 @@ func (t *Tile) Draw(boardImage *ebiten.Image) error { h := common.ArcadeFont.TextHeight(str) * scale x = x + (tileSize-w)/2 y = y + (tileSize-h)/2 - common.ArcadeFont.DrawText(boardImage, str, x, y, scale, tileColor(v)) + if err := common.ArcadeFont.DrawText(boardImage, str, x, y, scale, tileColor(v)); err != nil { + return err + } return nil } diff --git a/examples/2048/main.go b/examples/2048/main.go index 880d208d8..8e9c0818e 100644 --- a/examples/2048/main.go +++ b/examples/2048/main.go @@ -22,7 +22,7 @@ import ( ) var ( - game = twenty48.NewGame() + game *twenty48.Game ) func update(screen *ebiten.Image) error { @@ -39,6 +39,11 @@ func update(screen *ebiten.Image) error { } func main() { + var err error + game, err = twenty48.NewGame() + if err != nil { + log.Fatal(err) + } if err := ebiten.Run(update, twenty48.ScreenWidth, twenty48.ScreenHeight, 2, "2048 (Ebiten Demo)"); err != nil { log.Fatal(err) } diff --git a/examples/additive/main.go b/examples/additive/main.go index 2721e7fdd..e00a52e3c 100644 --- a/examples/additive/main.go +++ b/examples/additive/main.go @@ -37,14 +37,20 @@ func update(screen *ebiten.Image) error { const ox = 10 const oy = 10 - screen.Fill(color.NRGBA{0x00, 0x40, 0x80, 0xff}) + if err := screen.Fill(color.NRGBA{0x00, 0x40, 0x80, 0xff}); err != nil { + return err + } op := &ebiten.DrawImageOptions{} op.GeoM.Translate(ox, oy) - screen.DrawImage(ebitenImage, op) + if err := screen.DrawImage(ebitenImage, op); err != nil { + return err + } op = &ebiten.DrawImageOptions{} op.GeoM.Translate(ox+float64(w), oy) op.CompositeMode = ebiten.CompositeModeLighter - screen.DrawImage(ebitenImage, op) + if err := screen.DrawImage(ebitenImage, op); err != nil { + return err + } return nil } diff --git a/internal/loop/run.go b/internal/loop/run.go index 09bdaafb7..35d151e8f 100644 --- a/internal/loop/run.go +++ b/internal/loop/run.go @@ -101,10 +101,7 @@ func Run(g GraphicsContext, width, height int, scale float64, title string, fps } // TODO: Use the error value defer func() { - if err != nil { - return - } - err = ui.CurrentUI().Terminate() + _ = ui.CurrentUI().Terminate() }() n := now() diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 9c02ef859..2fbdd1db8 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -90,7 +90,6 @@ func (u *userInterface) main(ch <-chan error) error { return err } } - return nil } func (u *userInterface) runOnMainThread(f func() error) error {