mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
audio: Bug fix: possible overflow and closing nil channel
This commit is contained in:
parent
364819f361
commit
45ca2a1f79
@ -402,7 +402,6 @@ func (p *Player) readToBuffer(length int) (int, error) {
|
|||||||
if p.readingCh == nil {
|
if p.readingCh == nil {
|
||||||
p.readingCh = make(chan readingResult)
|
p.readingCh = make(chan readingResult)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(p.readingCh)
|
|
||||||
b := make([]uint8, length)
|
b := make([]uint8, length)
|
||||||
p.srcM.Lock()
|
p.srcM.Lock()
|
||||||
n, err := p.src.Read(b)
|
n, err := p.src.Read(b)
|
||||||
@ -422,19 +421,22 @@ func (p *Player) readToBuffer(length int) (int, error) {
|
|||||||
case pos := <-p.seekCh:
|
case pos := <-p.seekCh:
|
||||||
p.buf = []uint8{}
|
p.buf = []uint8{}
|
||||||
p.pos = pos
|
p.pos = pos
|
||||||
return 0, nil
|
|
||||||
case r := <-p.readingCh:
|
case r := <-p.readingCh:
|
||||||
|
close(p.readingCh)
|
||||||
|
p.readingCh = nil
|
||||||
if r.err != nil {
|
if r.err != nil {
|
||||||
return 0, r.err
|
return 0, r.err
|
||||||
}
|
}
|
||||||
if len(r.data) > 0 {
|
if len(r.data) > 0 {
|
||||||
p.buf = append(p.buf, r.data...)
|
p.buf = append(p.buf, r.data...)
|
||||||
}
|
}
|
||||||
p.readingCh = nil
|
|
||||||
return len(p.buf), nil
|
|
||||||
case <-time.After(15 * time.Millisecond):
|
case <-time.After(15 * time.Millisecond):
|
||||||
return length, nil
|
if l := length - len(p.buf); l > 0 {
|
||||||
|
empty := make([]uint8, l)
|
||||||
|
p.buf = append(p.buf, empty...)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return len(p.buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Player) bufferToInt16(lengthInBytes int) []int16 {
|
func (p *Player) bufferToInt16(lengthInBytes int) []int16 {
|
||||||
|
Loading…
Reference in New Issue
Block a user