mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-28 19:52:43 +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 {
|
func (p *playerImpl) Close() error {
|
||||||
p.mux.removePlayer(p)
|
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.m.Lock()
|
||||||
p.closedExplicitly = true
|
p.closedExplicitly = true
|
||||||
p.m.Unlock()
|
p.m.Unlock()
|
||||||
@ -365,9 +374,13 @@ func (p *playerImpl) ensureReadLoop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *playerImpl) closeImpl() error {
|
func (p *playerImpl) closeImpl() error {
|
||||||
if err := p.ensureReadLoop(); err != nil {
|
p.m.Lock()
|
||||||
return err
|
r := p.runningReadLoop
|
||||||
|
p.m.Unlock()
|
||||||
|
if !r {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
p.closeCh <- struct{}{}
|
p.closeCh <- struct{}{}
|
||||||
<-p.closedCh
|
<-p.closedCh
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user