Skip to content

Commit 9cb6c15

Browse files
committed
fix #535: Do not delete audio decoder in cloned sounds
1 parent 9232711 commit 9cb6c15

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/audio/internal/audioplayer.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ AudioPlayer::~AudioPlayer()
1818
{
1919
if (m_loaded) {
2020
ma_sound_uninit(m_sound);
21-
ma_decoder_uninit(m_decoder);
21+
22+
if (!m_copy)
23+
ma_decoder_uninit(m_decoder);
2224
}
2325

24-
delete m_decoder;
2526
delete m_sound;
27+
28+
if (!m_copy)
29+
delete m_decoder;
2630
}
2731

2832
bool AudioPlayer::load(unsigned int size, const void *data, unsigned long sampleRate)
@@ -74,6 +78,7 @@ bool AudioPlayer::loadCopy(IAudioPlayer *player)
7478
}
7579

7680
m_loaded = true;
81+
m_copy = true;
7782
ma_sound_set_volume(m_sound, m_volume);
7883
return true;
7984
}

src/audio/internal/audioplayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class AudioPlayer : public IAudioPlayer
3333
ma_decoder *m_decoder = nullptr;
3434
ma_sound *m_sound;
3535
bool m_loaded = false;
36+
bool m_copy = false;
3637
bool m_started = false;
3738
float m_volume = 1;
3839
};

0 commit comments

Comments
 (0)