From 65e8b487d21a68a04df0a0673d7322e7c7723bfd Mon Sep 17 00:00:00 2001 From: Ted Felix Date: Wed, 20 Mar 2024 21:08:08 -0400 Subject: [PATCH] Fix very rare crash on startup --- src/sound/AudioInstrumentMixer.cpp | 33 ++++++++++++------------------ src/sound/AudioProcess.h | 8 ++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/sound/AudioInstrumentMixer.cpp b/src/sound/AudioInstrumentMixer.cpp index c9fbe800f..2147a6460 100644 --- a/src/sound/AudioInstrumentMixer.cpp +++ b/src/sound/AudioInstrumentMixer.cpp @@ -14,7 +14,7 @@ */ #define RG_MODULE_STRING "[AudioInstrumentMixer]" -#define RG_NO_DEBUG_PRINT 1 +#define RG_NO_DEBUG_PRINT #include "AudioInstrumentMixer.h" @@ -105,7 +105,17 @@ AudioInstrumentMixer::AudioInstrumentMixer(SoundDriver *driver, pluginVector.resize(Instrument::PLUGIN_COUNT, nullptr); } -#ifndef NDEBUG + // Make room for the busses here. + const int bussCount = AudioBussMixer::getMaxBussCount(); + + // Submaster busses start at 1. Buss 0 is the master out and it cannot + // have effects plugins. + for (int i = 1; i < bussCount + 1; ++i) { + PluginList &pluginVector = m_plugins[i]; + pluginVector.resize(Instrument::PLUGIN_COUNT, nullptr); + } + +#if 0 RG_DEBUG << "ctor: m_plugins size:" << m_plugins.size(); for (const auto &pair : m_plugins) { RG_DEBUG << " [" << pair.first << "].size():" << pair.second.size(); @@ -133,7 +143,7 @@ AudioInstrumentMixer::getInstance() AudioInstrumentMixer::~AudioInstrumentMixer() { -#ifndef NDEBUG +#if 0 RG_DEBUG << "dtor: m_plugins size:" << m_plugins.size(); for (const auto &pair : m_plugins) { RG_DEBUG << " [" << pair.first << "].size():" << pair.second.size(); @@ -743,23 +753,6 @@ AudioInstrumentMixer::generateBuffers() } - // Make room for up to 16 busses here, to avoid reshuffling later - int busses = 16; - if (m_bussMixer) - busses = std::max(busses, m_bussMixer->getBussCount()); - for (int i = 0; i < busses; ++i) { - PluginList &list = m_plugins[i + 1]; - while ((unsigned int)list.size() < Instrument::PLUGIN_COUNT) { - // ??? NO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - // Well, here's the problem. These were supposed - // to be set up in advance so that we would never - // do this and therefore keep things thread safe. - // This throws that right out the window and explains - // the rare crashes I am seeing. - list.push_back(nullptr); - } - } - } void diff --git a/src/sound/AudioProcess.h b/src/sound/AudioProcess.h index 2627620c3..eb8482629 100644 --- a/src/sound/AudioProcess.h +++ b/src/sound/AudioProcess.h @@ -101,6 +101,14 @@ class AudioBussMixer : public AudioThread */ void emptyBuffers(); + /** + * Not sure this is the best place, but we really need this so that + * we can make the system easily expandable. + * + * I think we can only actually have 8, so 16 should be ok. + * Audio Mixer > Settings > Number of Submasters. + */ + static int getMaxBussCount() { return 16; } int getBussCount() const { return m_bussCount; }