Skip to content

Commit 8d9b08e

Browse files
committed
Fix sorter crashing when removing source processor
1 parent 8352891 commit 8d9b08e

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

Source/Plugins/SpikeSorter/SpikeSorter.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ void SpikeSorter::updateSettings()
172172
{
173173

174174
mut.enter();
175+
sorterReady = false;
175176
int numChannels = getNumInputs();
176177
if (numChannels > 0)
177178
overflowBuffer.setSize(getNumInputs(), overflowBufferSize);
@@ -191,7 +192,13 @@ void SpikeSorter::updateSettings()
191192
Array<const DataChannel*> chans;
192193
for (int c = 0; c < nChans; c++)
193194
{
194-
chans.add(getDataChannel(elec->channels[c]));
195+
const DataChannel* ch = getDataChannel(elec->channels[c]);
196+
if (!ch)
197+
{
198+
//not enough channels for the electrodes
199+
return;
200+
}
201+
chans.add(ch);
195202
}
196203

197204
SpikeChannel* spk = new SpikeChannel(SpikeChannel::typeFromNumChannels(nChans), this, chans);
@@ -200,7 +207,7 @@ void SpikeSorter::updateSettings()
200207

201208
spikeChannelArray.add(spk);
202209
}
203-
210+
sorterReady = true;
204211
mut.exit();
205212
}
206213

@@ -647,6 +654,12 @@ bool SpikeSorter::enable()
647654
{
648655

649656
useOverflowBuffer.clear();
657+
if (!sorterReady)
658+
{
659+
CoreServices::sendStatusMessage("Not enough channels for the configured electrodes");
660+
std::cout << "SpikeSorter: Not enough channels for the configured electrodes" << std::endl;
661+
return false;
662+
}
650663

651664
for (int i = 0; i < electrodes.size(); i++)
652665
useOverflowBuffer.add(false);

Source/Plugins/SpikeSorter/SpikeSorter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ class SpikeSorter : public GenericProcessor
427427
// RHD2000Thread* getRhythmAccess();
428428
bool flipSignal;
429429

430+
bool sorterReady{ false };
431+
430432
Time timer;
431433

432434
void addWaveformToSpikeObject(SpikeEvent::SpikeBuffer& s,

0 commit comments

Comments
 (0)