From a2483a839264369482fff135d33f007ded266d3c Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Wed, 4 Aug 2021 11:37:39 +0200 Subject: Fix crash when loading a kit with more channels than the engine was compiled for. --- src/inputprocessor.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/inputprocessor.cc') diff --git a/src/inputprocessor.cc b/src/inputprocessor.cc index abd2898..822e8b1 100644 --- a/src/inputprocessor.cc +++ b/src/inputprocessor.cc @@ -163,6 +163,11 @@ static void applyChokeGroup(Settings& settings, DrumKit& kit, // Add event to ramp down all existing events with the same groupname. for(const auto& ch : kit.channels) { + if(ch.num >= NUM_CHANNELS) // kit may have more channels than the engine + { + continue; + } + for(auto& event_sample : events_ds.iterateOver(ch.num)) { if(event_sample.group == instr.getGroup() && @@ -186,6 +191,11 @@ static void applyDirectedChoke(Settings& settings, DrumKit& kit, // Add event to ramp down all existing events with the same groupname. for(const auto& ch : kit.channels) { + if(ch.num >= NUM_CHANNELS) // kit may have more channels than the engine + { + continue; + } + for(auto& event_sample : events_ds.iterateOver(ch.num)) { if(choke.instrument_id == event_sample.instrument_id && @@ -264,6 +274,11 @@ bool InputProcessor::processOnset(event_t& event, std::size_t pos, bool new_group_added = false; for(Channel& ch: kit.channels) { + if(ch.num >= NUM_CHANNELS) // kit may have more channels than the engine + { + continue; + } + const auto af = sample->getAudioFile(ch); if(af == nullptr || !af->isValid()) { @@ -330,6 +345,11 @@ bool InputProcessor::processChoke(event_t& event, // Add event to ramp down all existing events with the same groupname. for(const auto& ch : kit.channels) { + if(ch.num >= NUM_CHANNELS) // kit may have more channels than the engine + { + continue; + } + for(auto& event_sample : events_ds.iterateOver(ch.num)) { if(event_sample.instrument_id == instrument_id && @@ -357,6 +377,11 @@ bool InputProcessor::processStop(event_t& event) int num_active_events = 0; for(auto& ch: kit.channels) { + if(ch.num >= NUM_CHANNELS) // kit may have more channels than the engine + { + continue; + } + num_active_events += events_ds.numberOfEvents(ch.num); } -- cgit v1.2.3