mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
parent
cde4c4fd2e
commit
e980d59191
@ -37,6 +37,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
@ -188,11 +189,15 @@ func (c *Context) addPlayingPlayer(p *playerImpl) {
|
||||
defer c.m.Unlock()
|
||||
c.playingPlayers[p] = struct{}{}
|
||||
|
||||
if !reflect.ValueOf(p.sourceIdent()).Comparable() {
|
||||
return
|
||||
}
|
||||
|
||||
// Check the source duplication
|
||||
srcs := map[any]struct{}{}
|
||||
for p := range c.playingPlayers {
|
||||
if _, ok := srcs[p.sourceIdent()]; ok {
|
||||
c.err = errors.New("audio: a same source is used by multiple Player")
|
||||
c.err = errors.New("audio: the same source must not be used by multiple Player objects")
|
||||
return
|
||||
}
|
||||
srcs[p.sourceIdent()] = struct{}{}
|
||||
|
@ -16,6 +16,7 @@ package audio_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
@ -147,4 +148,32 @@ func TestNonSeekableSource(t *testing.T) {
|
||||
|
||||
p.Play()
|
||||
p.Pause()
|
||||
|
||||
if err := audio.UpdateForTesting(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
type uncomparableSource []int
|
||||
|
||||
func (uncomparableSource) Read(buf []byte) (int, error) {
|
||||
return 0, io.EOF
|
||||
}
|
||||
|
||||
// Issue #3039
|
||||
func TestUncomparableSource(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
p, err := context.NewPlayer(uncomparableSource{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p.Play()
|
||||
p.Pause()
|
||||
|
||||
if err := audio.UpdateForTesting(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user