Skip to content

Commit

Permalink
Fix very rare crash on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
tedfelix committed Mar 21, 2024
1 parent c6f5d14 commit 65e8b48
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
33 changes: 13 additions & 20 deletions src/sound/AudioInstrumentMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

#define RG_MODULE_STRING "[AudioInstrumentMixer]"
#define RG_NO_DEBUG_PRINT 1
#define RG_NO_DEBUG_PRINT

#include "AudioInstrumentMixer.h"

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/sound/AudioProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 65e8b48

Please sign in to comment.