1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-12-25 11:36:26 -05:00

Fix background music crash issue. (#880)

* Added useful config error panic. Added window title to panic window.

* Fixed background music crash.
This commit is contained in:
Tim Sarbin 2020-10-28 22:34:47 -04:00 committed by GitHub
parent a9d832b539
commit ce36dec7f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

1
.gitignore vendored
View File

@ -13,3 +13,4 @@
tags tags
heap.out heap.out
heap.pdf heap.pdf
.DS_Store

View File

@ -2,6 +2,7 @@
package ebiten package ebiten
import ( import (
"io"
"log" "log"
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface" "github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
@ -31,6 +32,7 @@ type AudioProvider struct {
asset *d2asset.AssetManager asset *d2asset.AssetManager
audioContext *audio.Context // The Audio context audioContext *audio.Context // The Audio context
bgmAudio *audio.Player // The audio player bgmAudio *audio.Player // The audio player
bgmStream *wav.Stream
lastBgm string lastBgm string
sfxVolume float64 sfxVolume float64
bgmVolume float64 bgmVolume float64
@ -46,7 +48,6 @@ func (eap *AudioProvider) PlayBGM(song string) {
if song == "" && eap.bgmAudio != nil && eap.bgmAudio.IsPlaying() { if song == "" && eap.bgmAudio != nil && eap.bgmAudio.IsPlaying() {
eap.bgmAudio.Pause() eap.bgmAudio.Pause()
return return
} }
@ -64,13 +65,17 @@ func (eap *AudioProvider) PlayBGM(song string) {
panic(err) panic(err)
} }
d, err := wav.Decode(eap.audioContext, audioStream) if _, err = audioStream.Seek(0, io.SeekStart); err != nil {
log.Fatal(err)
}
eap.bgmStream, err = wav.Decode(eap.audioContext, audioStream)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
s := audio.NewInfiniteLoop(d, d.Length()) s := audio.NewInfiniteLoop(eap.bgmStream, eap.bgmStream.Length())
eap.bgmAudio, err = audio.NewPlayer(eap.audioContext, s) eap.bgmAudio, err = audio.NewPlayer(eap.audioContext, s)
if err != nil { if err != nil {