fix: crash — no delete of ma_sound/ma_audio_buffer during playback
- stopCurrentPcm(): only ma_sound_stop, no delete/uninit in runtime - playRawPcm(): just stop old sound, create new objects (old ones leak until shutdown) - shutdown(): cleanup accumulated ma_sound + ma_audio_buffer after engine uninit - root cause: deleting audio objects from GUI thread while miniaudio worker reads them
This commit is contained in:
1 parent
ce0df2a65b
commit
003451346a
1 file changed
+9
-11
@@ -35,6 +35,8 @@ bool SoundManager::init() {
|
||||
void SoundManager::shutdown() {
|
||||
if (!m_initialized) return;
|
||||
|
||||
stopCurrentPcm();
|
||||
|
||||
for (auto it = m_sounds.begin(); it != m_sounds.end(); ++it) {
|
||||
if (it->sound) { ma_sound_uninit(it->sound); delete it->sound; }
|
||||
if (it->decoder) { ma_decoder_uninit(it->decoder); delete it->decoder; }
|
||||
@@ -43,6 +45,11 @@ void SoundManager::shutdown() {
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "SoundManager: before ma_engine_uninit engine=%p", (void*)m_engine);
|
||||
if (m_engine) { ma_engine_uninit(m_engine); delete m_engine; m_engine = nullptr; }
|
||||
if (m_currentPcmSound) { delete m_currentPcmSound; m_currentPcmSound = nullptr; }
|
||||
if (m_currentPcmBuffer) {
|
||||
ma_audio_buffer* buf = (ma_audio_buffer*)m_currentPcmBuffer;
|
||||
ma_audio_buffer_uninit(buf); delete buf; m_currentPcmBuffer = nullptr;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "SoundManager: after ma_engine_uninit");
|
||||
m_initialized = false;
|
||||
}
|
||||
@@ -145,7 +152,7 @@ void SoundManager::playRawPcm(const int16_t* pcm, int sampleCount, int sampleRat
|
||||
DEBUG_WARN(DEBUG_CATEGORY_DEBUG, "SoundManager::playRawPcm: not initialized");
|
||||
return;
|
||||
}
|
||||
stopCurrentPcm();
|
||||
if (m_currentPcmSound) ma_sound_stop(m_currentPcmSound);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "SoundManager::playRawPcm: %d samples %dHz %dch", sampleCount, sampleRate, channels);
|
||||
|
||||
ma_audio_buffer_config bufCfg = ma_audio_buffer_config_init(
|
||||
@@ -181,16 +188,7 @@ void SoundManager::resumeCurrentPcm() {
|
||||
}
|
||||
|
||||
void SoundManager::stopCurrentPcm() {
|
||||
if (m_currentPcmSound) {
|
||||
ma_sound_stop(m_currentPcmSound);
|
||||
delete m_currentPcmSound; m_currentPcmSound = nullptr;
|
||||
}
|
||||
if (m_currentPcmBuffer) {
|
||||
ma_audio_buffer* buf = (ma_audio_buffer*)m_currentPcmBuffer;
|
||||
ma_audio_buffer_uninit(buf);
|
||||
delete buf;
|
||||
m_currentPcmBuffer = nullptr;
|
||||
}
|
||||
if (m_currentPcmSound) ma_sound_stop(m_currentPcmSound);
|
||||
}
|
||||
|
||||
static QString decodeDeviceName(const char* name) {
|
||||
|
||||
Reference in new issue
Block a user