Skip to content

Commit 0a61446

Browse files
committed
fix: freeze when game is paused
Pi would freeze if the user paused the game by holding the window title bar.
1 parent ddf7399 commit 0a61446

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

piebiten/internal/audio.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ func (p *player) Read(out []byte) (n int, err error) {
264264
defer p.mutex.Unlock()
265265

266266
n = len(out)
267-
p.time <- p.currentTime + sampleTime*float64(n)
267+
select {
268+
case p.time <- p.currentTime + sampleTime*float64(n):
269+
default:
270+
// discard the event when the game is paused and pi.Update is not run
271+
}
268272

269273
for i := 0; i < n; i += 4 {
270274
p.currentTime += sampleTime

0 commit comments

Comments
 (0)