mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +01:00
audio: Ensure Close is called at a readerPlayer is GCed
This commit is contained in:
parent
24973da123
commit
6f185063d6
@ -17,6 +17,7 @@ package audio
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -93,6 +94,7 @@ func (f *readerPlayerFactory) newPlayerImpl(context *Context, src io.Reader) (pl
|
|||||||
stream: s,
|
stream: s,
|
||||||
factory: f,
|
factory: f,
|
||||||
}
|
}
|
||||||
|
runtime.SetFinalizer(p, (*readerPlayer).Close)
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,8 +179,12 @@ func (p *readerPlayer) SetVolume(volume float64) {
|
|||||||
func (p *readerPlayer) Close() error {
|
func (p *readerPlayer) Close() error {
|
||||||
p.m.Lock()
|
p.m.Lock()
|
||||||
defer p.m.Unlock()
|
defer p.m.Unlock()
|
||||||
|
runtime.SetFinalizer(p, nil)
|
||||||
|
|
||||||
if p.player != nil {
|
if p.player != nil {
|
||||||
|
defer func() {
|
||||||
|
p.player = nil
|
||||||
|
}()
|
||||||
p.player.Pause()
|
p.player.Pause()
|
||||||
return p.player.Close()
|
return p.player.Close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user