mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +01:00
audio: Bug fix: Close always returned error
This commit is contained in:
parent
e4f0a0aa04
commit
9fc2ae158c
@ -341,6 +341,15 @@ func (p *Player) Close() error {
|
||||
|
||||
func (p *playerImpl) Close() error {
|
||||
p.mux.removePlayer(p)
|
||||
|
||||
p.m.Lock()
|
||||
c := p.closedExplicitly
|
||||
p.m.Unlock()
|
||||
if c {
|
||||
p.m.Unlock()
|
||||
return fmt.Errorf("audio: the player is already closed")
|
||||
}
|
||||
|
||||
p.m.Lock()
|
||||
p.closedExplicitly = true
|
||||
p.m.Unlock()
|
||||
@ -365,9 +374,13 @@ func (p *playerImpl) ensureReadLoop() error {
|
||||
}
|
||||
|
||||
func (p *playerImpl) closeImpl() error {
|
||||
if err := p.ensureReadLoop(); err != nil {
|
||||
return err
|
||||
p.m.Lock()
|
||||
r := p.runningReadLoop
|
||||
p.m.Unlock()
|
||||
if !r {
|
||||
return nil
|
||||
}
|
||||
|
||||
p.closeCh <- struct{}{}
|
||||
<-p.closedCh
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user