summaryrefslogtreecommitdiff
path: root/src/music
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-03-29 10:52:54 +0000
committerrubidium <rubidium@openttd.org>2009-03-29 10:52:54 +0000
commita4139d56931a25e5e44e29a9f671958057f701bf (patch)
tree13a164da583a302df811ef7ed374a2eb12019286 /src/music
parent9d2738b9c4c917fef1435276f7963c05fad817de (diff)
downloadopenttd-a4139d56931a25e5e44e29a9f671958057f701bf.tar.xz
(svn r15886) -Fix [FS#2770]: libtimidity cannot handle frees of NULL (in contrast of most other frees)
Diffstat (limited to 'src/music')
-rw-r--r--src/music/libtimidity.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/music/libtimidity.cpp b/src/music/libtimidity.cpp
index fe086c24d..eedc75d60 100644
--- a/src/music/libtimidity.cpp
+++ b/src/music/libtimidity.cpp
@@ -50,6 +50,7 @@ static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity;
const char *MusicDriver_LibTimidity::Start(const char * const *param)
{
_midi.status = MIDI_STOPPED;
+ _midi.song = NULL;
if (mid_init(param == NULL ? NULL : (char *)param[0]) < 0) {
/* If init fails, it can be because no configuration was found.
@@ -81,15 +82,14 @@ const char *MusicDriver_LibTimidity::Start(const char * const *param)
void MusicDriver_LibTimidity::Stop()
{
- if (_midi.status == MIDI_PLAYING) {
- _midi.status = MIDI_STOPPED;
- mid_song_free(_midi.song);
- }
+ if (_midi.status == MIDI_PLAYING) this->StopSong();
mid_exit();
}
void MusicDriver_LibTimidity::PlaySong(const char *filename)
{
+ this->StopSong();
+
_midi.stream = mid_istream_open_file(filename);
if (_midi.stream == NULL) {
DEBUG(driver, 0, "Could not open music file");
@@ -112,7 +112,9 @@ void MusicDriver_LibTimidity::PlaySong(const char *filename)
void MusicDriver_LibTimidity::StopSong()
{
_midi.status = MIDI_STOPPED;
- mid_song_free(_midi.song);
+ /* mid_song_free cannot handle NULL! */
+ if (_midi.song != NULL) mid_song_free(_midi.song);
+ _midi.song = NULL;
}
bool MusicDriver_LibTimidity::IsSongPlaying()
@@ -130,6 +132,5 @@ bool MusicDriver_LibTimidity::IsSongPlaying()
void MusicDriver_LibTimidity::SetVolume(byte vol)
{
- if (_midi.song != NULL)
- mid_song_set_volume(_midi.song, vol);
+ if (_midi.song != NULL) mid_song_set_volume(_midi.song, vol);
}