mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
bug fix: compile error with Go 1.16 and older
This commit is contained in:
parent
86ba7719eb
commit
e4fba8b047
@ -24,7 +24,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type playerState int
|
type playerState int
|
||||||
@ -129,7 +128,7 @@ type playerImpl struct {
|
|||||||
context *Context
|
context *Context
|
||||||
src io.Reader
|
src io.Reader
|
||||||
volume float64
|
volume float64
|
||||||
err atomic.Value
|
err atomicError
|
||||||
state playerState
|
state playerState
|
||||||
tmpbuf []byte
|
tmpbuf []byte
|
||||||
buf []byte
|
buf []byte
|
||||||
@ -395,6 +394,25 @@ func (p *playerImpl) readSourceToBuffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) setErrorImpl(err error) {
|
func (p *playerImpl) setErrorImpl(err error) {
|
||||||
p.err.CompareAndSwap(nil, err)
|
p.err.TryStore(err)
|
||||||
p.closeImpl()
|
p.closeImpl()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type atomicError struct {
|
||||||
|
err error
|
||||||
|
m sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *atomicError) TryStore(err error) {
|
||||||
|
a.m.Lock()
|
||||||
|
defer a.m.Unlock()
|
||||||
|
if a.err == nil {
|
||||||
|
a.err = err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *atomicError) Load() error {
|
||||||
|
a.m.Lock()
|
||||||
|
defer a.m.Unlock()
|
||||||
|
return a.err
|
||||||
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -7,7 +7,7 @@ require (
|
|||||||
github.com/hajimehoshi/bitmapfont/v2 v2.2.0
|
github.com/hajimehoshi/bitmapfont/v2 v2.2.0
|
||||||
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41
|
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41
|
||||||
github.com/hajimehoshi/go-mp3 v0.3.2
|
github.com/hajimehoshi/go-mp3 v0.3.2
|
||||||
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.7.0.20220307144353-ebc14f63b1c1
|
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.7.0.20220307150401-d142925f4f40
|
||||||
github.com/jakecoffman/cp v1.1.0
|
github.com/jakecoffman/cp v1.1.0
|
||||||
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240
|
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240
|
||||||
github.com/jfreymuth/oggvorbis v1.0.3
|
github.com/jfreymuth/oggvorbis v1.0.3
|
||||||
|
4
go.sum
4
go.sum
@ -9,8 +9,8 @@ github.com/hajimehoshi/go-mp3 v0.3.2 h1:xSYNE2F3lxtOu9BRjCWHHceg7S91IHfXfXp5+LYQ
|
|||||||
github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
|
github.com/hajimehoshi/go-mp3 v0.3.2/go.mod h1:qMJj/CSDxx6CGHiZeCgbiq2DSUkbK0UbtXShQcnfyMM=
|
||||||
github.com/hajimehoshi/oto v0.6.1 h1:7cJz/zRQV4aJvMSSRqzN2TImoVVMpE0BCY4nrNJaDOM=
|
github.com/hajimehoshi/oto v0.6.1 h1:7cJz/zRQV4aJvMSSRqzN2TImoVVMpE0BCY4nrNJaDOM=
|
||||||
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
|
github.com/hajimehoshi/oto v0.6.1/go.mod h1:0QXGEkbuJRohbJaxr7ZQSxnju7hEhseiPx2hrh6raOI=
|
||||||
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.7.0.20220307144353-ebc14f63b1c1 h1:i3nUxJnazLDnglzCtwoNmqX88Nf5JmRbKzJeQ4gCsr4=
|
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.7.0.20220307150401-d142925f4f40 h1:i1wPmufpfePzHxDJPiTX1tR2nvSVZ9JbUvKbTeVIzQ0=
|
||||||
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.7.0.20220307144353-ebc14f63b1c1/go.mod h1:rUKQmwMkqmRxe+IAof9+tuYA2ofm8cAWXFmSfzDN8vQ=
|
github.com/hajimehoshi/oto/v2 v2.1.0-alpha.7.0.20220307150401-d142925f4f40/go.mod h1:rUKQmwMkqmRxe+IAof9+tuYA2ofm8cAWXFmSfzDN8vQ=
|
||||||
github.com/jakecoffman/cp v1.1.0 h1:bhKvCNbAddYegYHSV5abG3G23vZdsISgqXa4X/lK8Oo=
|
github.com/jakecoffman/cp v1.1.0 h1:bhKvCNbAddYegYHSV5abG3G23vZdsISgqXa4X/lK8Oo=
|
||||||
github.com/jakecoffman/cp v1.1.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
|
github.com/jakecoffman/cp v1.1.0/go.mod h1:JjY/Fp6d8E1CHnu74gWNnU0+b9VzEdUVPoJxg2PsTQg=
|
||||||
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 h1:dy+DS31tGEGCsZzB45HmJJNHjur8GDgtRNX9U7HnSX4=
|
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 h1:dy+DS31tGEGCsZzB45HmJJNHjur8GDgtRNX9U7HnSX4=
|
||||||
|
@ -174,7 +174,9 @@ var theGlobalState = globalState{
|
|||||||
// globalState represents a global state in this package.
|
// globalState represents a global state in this package.
|
||||||
// This is available even before the game loop starts.
|
// This is available even before the game loop starts.
|
||||||
type globalState struct {
|
type globalState struct {
|
||||||
err_ atomic.Value
|
err_ error
|
||||||
|
errM sync.Mutex
|
||||||
|
|
||||||
fpsMode_ int32
|
fpsMode_ int32
|
||||||
maxTPS_ int32
|
maxTPS_ int32
|
||||||
isScreenClearedEveryFrame_ int32
|
isScreenClearedEveryFrame_ int32
|
||||||
@ -182,15 +184,17 @@ type globalState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *globalState) error() error {
|
func (g *globalState) error() error {
|
||||||
err, ok := g.err_.Load().(error)
|
g.errM.Lock()
|
||||||
if !ok {
|
defer g.errM.Unlock()
|
||||||
return nil
|
return g.err_
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *globalState) setError(err error) {
|
func (g *globalState) setError(err error) {
|
||||||
g.err_.CompareAndSwap(nil, err)
|
g.errM.Lock()
|
||||||
|
defer g.errM.Unlock()
|
||||||
|
if g.err_ == nil {
|
||||||
|
g.err_ = err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *globalState) fpsMode() FPSModeType {
|
func (g *globalState) fpsMode() FPSModeType {
|
||||||
|
Loading…
Reference in New Issue
Block a user