add errcheck static analysis (#2293)

Closes #2287
This commit is contained in:
Terra Brown 2022-09-09 12:52:46 -04:00 committed by GitHub
parent e505098e55
commit a1cc44833d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 133 additions and 45 deletions

View File

@ -73,10 +73,11 @@ jobs:
run: | run: |
go vet -tags=example -v ./... go vet -tags=example -v ./...
- name: go vet (atomic align) - name: go vet (atomic align, error check)
if: ${{ !startsWith(matrix.os, 'windows-') }} # TODO: Fix go vet errors on Windows. (#1306)
run: | run: |
go install .github/workflows/vettools/atomicalign.go go install .github/workflows/vettools/vettools.go
go vet -vettool=$(which atomicalign)${{ startsWith(matrix.os, 'windows-') && '.exe' || '' }} -tags=example -v ./... go vet -vettool=$(which vettools)${{ startsWith(matrix.os, 'windows-') && '.exe' || '' }} -tags=example -v ./...
- name: go build - name: go build
run: | run: |

View File

@ -18,10 +18,28 @@
package main package main
import ( import (
"os"
"runtime"
"github.com/kisielk/errcheck/errcheck"
"golang.org/x/tools/go/analysis/multichecker" "golang.org/x/tools/go/analysis/multichecker"
"golang.org/x/tools/go/analysis/passes/atomicalign" "golang.org/x/tools/go/analysis/passes/atomicalign"
) )
func main() { func main() {
multichecker.Main(atomicalign.Analyzer) GOOS, ok := os.LookupEnv("GOOS")
if !ok {
GOOS = runtime.GOOS
}
for _, filename := range []string{
".errcheck_excludes",
".errcheck_excludes_" + GOOS,
} {
if _, err := os.Stat(filename); err == nil {
errcheck.Analyzer.Flags.Set("exclude", filename)
}
}
multichecker.Main(atomicalign.Analyzer, errcheck.Analyzer)
} }

View File

@ -339,7 +339,7 @@ func NewPlayerFromBytes(context *Context, src []byte) *Player {
func (p *Player) finalize() { func (p *Player) finalize() {
runtime.SetFinalizer(p, nil) runtime.SetFinalizer(p, nil)
if !p.IsPlaying() { if !p.IsPlaying() {
p.Close() _ = p.Close()
} }
} }

View File

@ -111,7 +111,7 @@ func prepareGomobileCommands() (string, error) {
return tmp, err return tmp, err
} }
defer func() { defer func() {
os.Chdir(pwd) _ = os.Chdir(pwd)
}() }()
const ( const (

View File

@ -117,7 +117,7 @@ func main() {
flagset.StringVar(&bindClasspath, "classpath", "", "") flagset.StringVar(&bindClasspath, "classpath", "", "")
flagset.StringVar(&bindBootClasspath, "bootclasspath", "", "") flagset.StringVar(&bindBootClasspath, "bootclasspath", "", "")
flagset.Parse(args[1:]) _ = flagset.Parse(args[1:])
buildTarget, err := osFromBuildTarget(buildTarget) buildTarget, err := osFromBuildTarget(buildTarget)
if err != nil { if err != nil {
@ -136,7 +136,7 @@ func main() {
dir, err := prepareGomobileCommands() dir, err := prepareGomobileCommands()
defer func() { defer func() {
if dir != "" && !buildWork { if dir != "" && !buildWork {
removeAll(dir) _ = removeAll(dir)
} }
}() }()
if err != nil { if err != nil {
@ -225,7 +225,9 @@ func doBind(args []string, flagset *flag.FlagSet, buildOS string) error {
if err != nil { if err != nil {
return err return err
} }
defer f.Close() defer func() {
_ = f.Close()
}()
names, err := f.Readdirnames(-1) names, err := f.Readdirnames(-1)
if err != nil { if err != nil {
@ -265,7 +267,9 @@ func doBind(args []string, flagset *flag.FlagSet, buildOS string) error {
if err != nil { if err != nil {
return err return err
} }
defer w.Close() defer func() {
_ = w.Close()
}()
var mmVals = struct { var mmVals = struct {
Module string Module string
Headers []string Headers []string

View File

@ -33,7 +33,9 @@ func NewImageFromFileSystem(fs fs.FS, path string) (*ebiten.Image, image.Image,
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
defer file.Close() defer func() {
_ = file.Close()
}()
img, _, err := image.Decode(file) img, _, err := image.Decode(file)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err

View File

@ -44,7 +44,9 @@ func NewImageFromURL(url string) (*ebiten.Image, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer res.Body.Close() defer func() {
_ = res.Body.Close()
}()
img, _, err := image.Decode(res.Body) img, _, err := image.Decode(res.Body)
if err != nil { if err != nil {

View File

@ -246,7 +246,9 @@ func (g *Game) Update() error {
g.cameraX += 2 g.cameraX += 2
if g.isKeyJustPressed() { if g.isKeyJustPressed() {
g.vy16 = -96 g.vy16 = -96
g.jumpPlayer.Rewind() if err := g.jumpPlayer.Rewind(); err != nil {
return err
}
g.jumpPlayer.Play() g.jumpPlayer.Play()
} }
g.y16 += g.vy16 g.y16 += g.vy16
@ -258,7 +260,9 @@ func (g *Game) Update() error {
} }
if g.hit() { if g.hit() {
g.hitPlayer.Rewind() if err := g.hitPlayer.Rewind(); err != nil {
return err
}
g.hitPlayer.Play() g.hitPlayer.Play()
g.mode = ModeGameOver g.mode = ModeGameOver
g.gameoverCount = 30 g.gameoverCount = 30

View File

@ -80,7 +80,10 @@ func (g *Game) Update() error {
if inpututil.IsKeyJustPressed(ebiten.KeyP) { if inpututil.IsKeyJustPressed(ebiten.KeyP) {
// As audioPlayer has one stream and remembers the playing position, // As audioPlayer has one stream and remembers the playing position,
// rewinding is needed before playing when reusing audioPlayer. // rewinding is needed before playing when reusing audioPlayer.
g.audioPlayer.Rewind() if err := g.audioPlayer.Rewind(); err != nil {
return err
}
g.audioPlayer.Play() g.audioPlayer.Play()
} }
return nil return nil

1
go.mod
View File

@ -11,6 +11,7 @@ require (
github.com/jakecoffman/cp v1.2.1 github.com/jakecoffman/cp v1.2.1
github.com/jezek/xgb v1.0.1 github.com/jezek/xgb v1.0.1
github.com/jfreymuth/oggvorbis v1.0.4 github.com/jfreymuth/oggvorbis v1.0.4
github.com/kisielk/errcheck v1.6.2 // indirect
golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 golang.org/x/image v0.0.0-20220722155232-062f8c9fd539
golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105 golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 golang.org/x/sys v0.0.0-20220818161305-2296e01440c6

7
go.sum
View File

@ -19,8 +19,11 @@ github.com/jfreymuth/oggvorbis v1.0.4 h1:cyJCd0XSoxkKzUPmqM0ZoQJ0h/WbhfyvUR+FTMx
github.com/jfreymuth/oggvorbis v1.0.4/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII= github.com/jfreymuth/oggvorbis v1.0.4/go.mod h1:1U4pqWmghcoVsCJJ4fRBKv9peUJMBHixthRlBeD6uII=
github.com/jfreymuth/vorbis v1.0.2 h1:m1xH6+ZI4thH927pgKD8JOH4eaGRm18rEE9/0WKjvNE= github.com/jfreymuth/vorbis v1.0.2 h1:m1xH6+ZI4thH927pgKD8JOH4eaGRm18rEE9/0WKjvNE=
github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ= github.com/jfreymuth/vorbis v1.0.2/go.mod h1:DoftRo4AznKnShRl1GxiTFCseHr4zR9BN3TWXyuzrqQ=
github.com/kisielk/errcheck v1.6.2 h1:uGQ9xI8/pgc9iOoCe7kWQgRE6SBTrCGmTSf0LrEtY7c=
github.com/kisielk/errcheck v1.6.2/go.mod h1:nXw/i/MfnvRHqXa7XXmQMUB0oNFGuBrNI8d8NLy0LPw=
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
@ -39,6 +42,7 @@ golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105 h1:3vUV5x5+3LfQbgk7paCM6I
golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ= golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@ -46,6 +50,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@ -59,6 +64,7 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@ -75,6 +81,7 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo= golang.org/x/tools v0.1.8-0.20211022200916-316ba0b74098/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

View File

@ -0,0 +1 @@
syscall.Syscall

View File

@ -612,7 +612,7 @@ func (g *nativeGamepadDesktop) update(gamepads *gamepads) (err error) {
return err return err
} }
// Acquire can return an error just after a gamepad is disconnected. Ignore the error. // Acquire can return an error just after a gamepad is disconnected. Ignore the error.
g.dinputDevice.Acquire() _ = g.dinputDevice.Acquire()
if err := g.dinputDevice.Poll(); err != nil { if err := g.dinputDevice.Poll(); err != nil {
if !errors.Is(err, directInputError(_DIERR_NOTACQUIRED)) && !errors.Is(err, directInputError(_DIERR_INPUTLOST)) { if !errors.Is(err, directInputError(_DIERR_NOTACQUIRED)) && !errors.Is(err, directInputError(_DIERR_INPUTLOST)) {
return err return err

View File

@ -120,7 +120,7 @@ func (*nativeGamepadsImpl) openGamepad(gamepads *gamepads, path string) (err err
} }
defer func() { defer func() {
if err != nil { if err != nil {
unix.Close(fd) _ = unix.Close(fd)
} }
}() }()
@ -142,11 +142,17 @@ func (*nativeGamepadsImpl) openGamepad(gamepads *gamepads, path string) (err err
} }
if !isBitSet(evBits, unix.EV_KEY) { if !isBitSet(evBits, unix.EV_KEY) {
unix.Close(fd) if err := unix.Close(fd); err != nil {
return err
}
return nil return nil
} }
if !isBitSet(evBits, unix.EV_ABS) { if !isBitSet(evBits, unix.EV_ABS) {
unix.Close(fd) if err := unix.Close(fd); err != nil {
return err
}
return nil return nil
} }
@ -294,7 +300,7 @@ type nativeGamepadImpl struct {
func (g *nativeGamepadImpl) close() { func (g *nativeGamepadImpl) close() {
if g.fd != 0 { if g.fd != 0 {
unix.Close(g.fd) _ = unix.Close(g.fd)
} }
g.fd = 0 g.fd = 0
} }
@ -337,7 +343,9 @@ func (g *nativeGamepadImpl) update(gamepad *gamepads) error {
g.dropped = true g.dropped = true
case _SYN_REPORT: case _SYN_REPORT:
g.dropped = false g.dropped = false
g.pollAbsState() if err := g.pollAbsState(); err != nil {
return fmt.Errorf("gamepad: poll absolute state: %w", err)
}
} }
} }
if g.dropped { if g.dropped {

View File

@ -0,0 +1,2 @@
syscall.Syscall
(*golang.org/x/sys/windows.LazyProc).Call

View File

@ -444,7 +444,9 @@ func (w *Window) refreshContextAttribs(ctxconfig *ctxconfig) (ferr error) {
syscall.Syscall(glClear, 1, GL_COLOR_BUFFER_BIT, 0, 0) syscall.Syscall(glClear, 1, GL_COLOR_BUFFER_BIT, 0, 0)
if w.doublebuffer { if w.doublebuffer {
w.context.swapBuffers(w) if err := w.context.swapBuffers(w); err != nil {
return err
}
} }
return nil return nil

View File

@ -36,7 +36,7 @@ func terminate() error {
func Init() (ferr error) { func Init() (ferr error) {
defer func() { defer func() {
if ferr != nil { if ferr != nil {
terminate() _ = terminate()
} }
}() }()

View File

@ -335,7 +335,7 @@ func CreateCursor(image *Image, xhot, yhot int) (*Cursor, error) {
_glfw.cursors = append(_glfw.cursors, cursor) _glfw.cursors = append(_glfw.cursors, cursor)
if err := cursor.platformCreateCursor(image, xhot, yhot); err != nil { if err := cursor.platformCreateCursor(image, xhot, yhot); err != nil {
cursor.Destroy() _ = cursor.Destroy()
return nil, err return nil, err
} }
@ -360,7 +360,7 @@ func CreateStandardCursor(shape StandardCursor) (*Cursor, error) {
_glfw.cursors = append(_glfw.cursors, cursor) _glfw.cursors = append(_glfw.cursors, cursor)
if err := cursor.platformCreateStandardCursor(shape); err != nil { if err := cursor.platformCreateStandardCursor(shape); err != nil {
cursor.Destroy() _ = cursor.Destroy()
return nil, err return nil, err
} }

View File

@ -82,12 +82,16 @@ func inputMonitor(monitor *Monitor, action PeripheralEvent, placement int) error
if err != nil { if err != nil {
return err return err
} }
window.platformSetWindowMonitor(nil, 0, 0, width, height, 0) if err := window.platformSetWindowMonitor(nil, 0, 0, width, height, 0); err != nil {
return err
}
xoff, yoff, _, _, err := window.platformGetWindowFrameSize() xoff, yoff, _, _, err := window.platformGetWindowFrameSize()
if err != nil { if err != nil {
return err return err
} }
window.platformSetWindowPos(xoff, yoff) if err := window.platformSetWindowPos(xoff, yoff); err != nil {
return err
}
} }
} }
for i, m := range _glfw.monitors { for i, m := range _glfw.monitors {

View File

@ -208,7 +208,7 @@ func (w *Window) choosePixelFormat(ctxconfig *ctxconfig, fbconfig_ *fbconfig) (i
func makeContextCurrentWGL(window *Window) error { func makeContextCurrentWGL(window *Window) error {
if window != nil { if window != nil {
if err := wglMakeCurrent(window.context.wgl.dc, window.context.wgl.handle); err != nil { if err := wglMakeCurrent(window.context.wgl.dc, window.context.wgl.handle); err != nil {
_glfw.contextSlot.set(0) _ = _glfw.contextSlot.set(0)
return err return err
} }
if err := _glfw.contextSlot.set(uintptr(unsafe.Pointer(window))); err != nil { if err := _glfw.contextSlot.set(uintptr(unsafe.Pointer(window))); err != nil {
@ -216,7 +216,7 @@ func makeContextCurrentWGL(window *Window) error {
} }
} else { } else {
if err := wglMakeCurrent(0, 0); err != nil { if err := wglMakeCurrent(0, 0); err != nil {
_glfw.contextSlot.set(0) _ = _glfw.contextSlot.set(0)
return err return err
} }
if err := _glfw.contextSlot.set(0); err != nil { if err := _glfw.contextSlot.set(0); err != nil {
@ -378,8 +378,8 @@ func initWGL() error {
prc := wglGetCurrentContext() prc := wglGetCurrentContext()
if err := wglMakeCurrent(dc, rc); err != nil { if err := wglMakeCurrent(dc, rc); err != nil {
wglMakeCurrent(pdc, prc) _ = wglMakeCurrent(pdc, prc)
wglDeleteContext(rc) _ = wglDeleteContext(rc)
return err return err
} }

View File

@ -105,7 +105,11 @@ adapterLoop:
for i, monitor := range disconnected { for i, monitor := range disconnected {
if monitor != nil && monitor.win32.displayName == windows.UTF16ToString(display.DeviceName[:]) { if monitor != nil && monitor.win32.displayName == windows.UTF16ToString(display.DeviceName[:]) {
disconnected[i] = nil disconnected[i] = nil
_EnumDisplayMonitors(0, nil, monitorCallbackPtr, _LPARAM(unsafe.Pointer(_glfw.monitors[i]))) err := _EnumDisplayMonitors(0, nil, monitorCallbackPtr, _LPARAM(unsafe.Pointer(_glfw.monitors[i])))
if err != nil {
return err
}
continue displayLoop continue displayLoop
} }
} }

View File

@ -87,13 +87,17 @@ func createIcon(image *Image, xhot, yhot int, icon bool) (_HICON, error) {
if err != nil { if err != nil {
return 0, err return 0, err
} }
defer _DeleteObject(_HGDIOBJ(color)) defer func() {
_ = _DeleteObject(_HGDIOBJ(color))
}()
mask, err := _CreateBitmap(int32(image.Width), int32(image.Height), 1, 1, nil) mask, err := _CreateBitmap(int32(image.Width), int32(image.Height), 1, 1, nil)
if err != nil { if err != nil {
return 0, err return 0, err
} }
defer _DeleteObject(_HGDIOBJ(mask)) defer func() {
_ = _DeleteObject(_HGDIOBJ(mask))
}()
source := image.Pixels source := image.Pixels
var target []byte var target []byte
@ -396,7 +400,9 @@ func (w *Window) updateFramebufferTransparency() error {
if err != nil { if err != nil {
return err return err
} }
defer _DeleteObject(_HGDIOBJ(region)) defer func() {
_ = _DeleteObject(_HGDIOBJ(region))
}()
bb := _DWM_BLURBEHIND{ bb := _DWM_BLURBEHIND{
dwFlags: _DWM_BB_ENABLE | _DWM_BB_BLURREGION, dwFlags: _DWM_BB_ENABLE | _DWM_BB_BLURREGION,
@ -1444,7 +1450,9 @@ func (w *Window) platformDestroyWindow() error {
} }
if w.context.destroy != nil { if w.context.destroy != nil {
w.context.destroy(w) if err := w.context.destroy(w); err != nil {
return err
}
} }
if _glfw.win32.disabledCursorWindow == w { if _glfw.win32.disabledCursorWindow == w {

View File

@ -136,7 +136,7 @@ func CreateWindow(width, height int, title string, monitor *Monitor, share *Wind
} }
defer func() { defer func() {
if ferr != nil { if ferr != nil {
window.Destroy() _ = window.Destroy()
} }
}() }()
_glfw.windows = append(_glfw.windows, window) _glfw.windows = append(_glfw.windows, window)
@ -313,7 +313,10 @@ func (w *Window) Destroy() error {
} }
} }
w.platformDestroyWindow() if err := w.platformDestroyWindow(); err != nil {
return err
}
return nil return nil
} }

View File

@ -78,7 +78,7 @@ func DumpImages(images []*Image, graphicsDriver graphicsdriver.Graphics, dir str
} }
} }
zw.Close() _ = zw.Close()
zip := dir + ".zip" zip := dir + ".zip"
download(buf, "archive/zip", zip) download(buf, "archive/zip", zip)

View File

@ -39,7 +39,9 @@ func (i *Image) Dump(graphicsDriver graphicsdriver.Graphics, path string, blackb
if err != nil { if err != nil {
return "", err return "", err
} }
defer f.Close() defer func() {
_ = f.Close()
}()
if err := i.dumpTo(f, graphicsDriver, blackbg, rect); err != nil { if err := i.dumpTo(f, graphicsDriver, blackbg, rect); err != nil {
return "", err return "", err
@ -72,7 +74,9 @@ func DumpImages(images []*Image, graphicsDriver graphicsdriver.Graphics, dir str
if err != nil { if err != nil {
return "", err return "", err
} }
defer f.Close() defer func() {
_ = f.Close()
}()
if err := img.dumpTo(f, graphicsDriver, false, image.Rect(0, 0, img.width, img.height)); err != nil { if err := img.dumpTo(f, graphicsDriver, false, image.Rect(0, 0, img.width, img.height)); err != nil {
return "", err return "", err

View File

@ -0,0 +1,4 @@
syscall.Syscall
syscall.Syscall6
syscall.Syscall9
syscall.Syscall12

View File

@ -860,12 +860,11 @@ func (g *Graphics) presentDesktop() error {
} }
func (g *Graphics) presentXbox() error { func (g *Graphics) presentXbox() error {
g.commandQueue.PresentX(1, &_D3D12XBOX_PRESENT_PLANE_PARAMETERS{ return g.commandQueue.PresentX(1, &_D3D12XBOX_PRESENT_PLANE_PARAMETERS{
Token: g.framePipelineToken, Token: g.framePipelineToken,
ResourceCount: 1, ResourceCount: 1,
ppResources: &g.renderTargets[g.frameIndex], ppResources: &g.renderTargets[g.frameIndex],
}, nil) }, nil)
return nil
} }
func (g *Graphics) moveToNextFrame() error { func (g *Graphics) moveToNextFrame() error {

View File

@ -144,7 +144,9 @@ func readPNG(name string) (image.Image, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer f.Close() defer func() {
_ = f.Close()
}()
return png.Decode(f) return png.Decode(f)
} }

View File

@ -0,0 +1,3 @@
syscall.Syscall
syscall.Syscall6
syscall.Syscall9

View File

@ -0,0 +1,2 @@
(io.ReadCloser).Close
(*compress/zlib.Writer).Close

View File

@ -67,6 +67,6 @@ func hideConsoleWindowOnWindows() {
if pid == cpid { if pid == cpid {
// The current process created its own console. Hide this. // The current process created its own console. Hide this.
// Ignore error. // Ignore error.
freeConsole() _ = freeConsole()
} }
} }