Skip to content

Commit fe35b76

Browse files
committed
Fix crashes in PopupConfigurationWindow
1 parent 3dcb9ff commit fe35b76

3 files changed

Lines changed: 65 additions & 52 deletions

File tree

Plugins/SpikeDetector/PopupConfigurationWindow.cpp

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ ThresholdSelectorCustomComponent::~ThresholdSelectorCustomComponent()
251251

252252
void ThresholdSelectorCustomComponent::mouseDown (const MouseEvent& event)
253253
{
254-
if (channel == nullptr)
254+
if (channel == nullptr || ! channel->isValid())
255255
return;
256256

257257
auto* popupComponent = new PopupThresholdComponent (table,
@@ -334,7 +334,9 @@ void ThresholdSelectorCustomComponent::paint (Graphics& g)
334334

335335
thresholdString = thresholdString.substring (0, thresholdString.length() - 1);
336336

337-
g.setColour (findColour (ThemeColours::defaultText));
337+
float alpha = getParentComponent()->isEnabled() ? 1.0f : 0.5f;
338+
339+
g.setColour (findColour (ThemeColours::defaultText).withAlpha (alpha));
338340
g.setFont (FontOptions ("Inter", "Regular", 14.0f));
339341
g.drawFittedText (thresholdString, 4, 0, getWidth() - 8, getHeight(), Justification::centredLeft, 1, 0.75f);
340342
}
@@ -380,7 +382,7 @@ void ChannelSelectorCustomComponent::showAsPopup()
380382

381383
void ChannelSelectorCustomComponent::mouseDown (const juce::MouseEvent& event)
382384
{
383-
if (acquisitionIsActive)
385+
if (acquisitionIsActive || ! getParentComponent()->isEnabled())
384386
return;
385387

386388
showAsPopup();
@@ -449,7 +451,7 @@ void WaveformSelectorCustomComponent::setRowAndColumn (const int newRow, const i
449451

450452
void DeleteButtonCustomComponent::mouseDown (const juce::MouseEvent& event)
451453
{
452-
if (acquisitionIsActive)
454+
if (acquisitionIsActive || ! getParentComponent()->isEnabled())
453455
return;
454456

455457
table->deleteSelectedRows (row);
@@ -460,7 +462,7 @@ void DeleteButtonCustomComponent::paint (Graphics& g)
460462
int width = getWidth();
461463
int height = getHeight();
462464

463-
if (acquisitionIsActive)
465+
if (acquisitionIsActive || ! getParentComponent()->isEnabled())
464466
{
465467
g.setColour (Colours::grey);
466468
}
@@ -471,7 +473,7 @@ void DeleteButtonCustomComponent::paint (Graphics& g)
471473

472474
g.fillEllipse (7, 7, width - 14, height - 14);
473475
g.setColour (Colours::white);
474-
g.fillRect (9, (height / 2) - 2, width - 19, 3);
476+
g.fillRect (9, (height / 2) - 1, width - 19, 2);
475477
}
476478

477479
void DeleteButtonCustomComponent::setRowAndColumn (const int newRow, const int newColumn)
@@ -758,6 +760,15 @@ void SpikeDetectorTableModel::update (Array<SpikeChannel*> spikeChannels_)
758760

759761
table->updateContent();
760762

763+
if (spikeChannels.size() > 0 && ! spikeChannels[0]->isValid())
764+
{
765+
table->setEnabled (false);
766+
}
767+
else
768+
{
769+
table->setEnabled (true);
770+
}
771+
761772
waveformComponents.clear();
762773
thresholdComponents.clear();
763774

@@ -781,33 +792,23 @@ void SpikeDetectorTableModel::paintRowBackground (Graphics& g, int rowNumber, in
781792
if (rowNumber >= spikeChannels.size())
782793
return;
783794

784-
if (rowIsSelected)
785-
{
786-
if (rowNumber % 2 == 0)
787-
g.fillAll (owner->findColour (ThemeColours::componentBackground));
788-
else
789-
g.fillAll (owner->findColour (ThemeColours::componentBackground).darker (0.25f));
790-
791-
g.setColour (owner->findColour (ThemeColours::highlightedFill));
792-
g.drawRoundedRectangle (2, 2, width - 4, height - 4, 5, 2);
793-
794-
return;
795-
}
795+
Colour rowColour;
796796

797797
if (spikeChannels[rowNumber]->isValid())
798-
{
799-
if (rowNumber % 2 == 0)
800-
g.fillAll (owner->findColour (ThemeColours::componentBackground));
801-
else
802-
g.fillAll (owner->findColour (ThemeColours::componentBackground).darker (0.25f));
803-
804-
return;
805-
}
798+
rowColour = owner->findColour (ThemeColours::componentBackground);
799+
else
800+
rowColour = Colour (90, 50, 50);
806801

807802
if (rowNumber % 2 == 0)
808-
g.fillAll (Colour (90, 50, 50));
803+
g.fillAll (rowColour);
809804
else
810-
g.fillAll (Colour (60, 30, 30));
805+
g.fillAll (rowColour.darker (0.25f));
806+
807+
if (rowIsSelected)
808+
{
809+
g.setColour (owner->findColour (ThemeColours::highlightedFill));
810+
g.drawRoundedRectangle (2, 2, width - 4, height - 4, 5, 2);
811+
}
811812
}
812813

813814
void SpikeDetectorTableModel::paintCell (Graphics& g, int rowNumber, int columnId, int width, int height, bool rowIsSelected)
@@ -1055,8 +1056,14 @@ PopupConfigurationWindow::PopupConfigurationWindow (SpikeDetectorEditor* editor_
10551056
addAndMakeVisible (viewport.get());
10561057
update (spikeChannels);
10571058

1058-
auto stream = editor->getProcessor()->getDataStream (editor->getCurrentStream());
1059-
popupTitle = String(stream->getSourceNodeId()) + " " + stream->getSourceNodeName() + " - " + stream->getName();
1059+
if (auto stream = editor->getProcessor()->getDataStream (editor->getCurrentStream()))
1060+
{
1061+
popupTitle = String (stream->getSourceNodeId()) + " " + stream->getSourceNodeName() + " - " + stream->getName();
1062+
}
1063+
else
1064+
{
1065+
popupTitle = "No streams available";
1066+
}
10601067
}
10611068

10621069
void PopupConfigurationWindow::scrollBarMoved (ScrollBar* scrollBar, double newRangeStart)
@@ -1128,12 +1135,13 @@ void PopupConfigurationWindow::paint (Graphics& g)
11281135
bool PopupConfigurationWindow::keyPressed (const KeyPress& key)
11291136
{
11301137
// Popup component handles globally reserved undo/redo keys
1131-
PopupComponent::keyPressed (key);
1132-
1133-
// Pressing 'a' key adds a new spike channel
1134-
if (key.getTextCharacter() == 'a')
1138+
if (! PopupComponent::keyPressed (key))
11351139
{
1136-
editor->addSpikeChannels (this, spikeChannelGenerator->getSelectedType(), 1);
1140+
// Pressing 'a' key adds a new spike channel
1141+
if (key.getTextCharacter() == 'a')
1142+
{
1143+
editor->addSpikeChannels (this, spikeChannelGenerator->getSelectedType(), 1);
1144+
}
11371145
}
11381146

11391147
return true;

Plugins/SpikeDetector/SpikeDetectorEditor.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,34 @@ void SpikeDetectorEditor::addSpikeChannels (PopupConfigurationWindow* window, Sp
8080
{
8181
SpikeDetector* processor = (SpikeDetector*) getProcessor();
8282

83-
DataStream* stream = processor->getDataStream (getCurrentStream());
84-
85-
int nextAvailableChannel = processor->getNextAvailableChannelForStream (stream->getStreamId());
83+
if (auto stream = processor->getDataStream (getCurrentStream()))
84+
{
85+
int nextAvailableChannel = processor->getNextAvailableChannelForStream (stream->getStreamId());
8686

87-
AddSpikeChannels* action = new AddSpikeChannels (processor, stream, type, count, startChannels, nextAvailableChannel);
87+
AddSpikeChannels* action = new AddSpikeChannels (processor, stream, type, count, startChannels, nextAvailableChannel);
8888

89-
CoreServices::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
90-
CoreServices::getUndoManager()->perform ((UndoableAction*) action);
89+
CoreServices::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
90+
CoreServices::getUndoManager()->perform ((UndoableAction*) action);
9191

92-
if (window != nullptr)
93-
window->update (processor->getSpikeChannelsForStream (getCurrentStream()));
92+
if (window != nullptr)
93+
window->update (processor->getSpikeChannelsForStream (getCurrentStream()));
94+
}
9495
}
9596

9697
void SpikeDetectorEditor::removeSpikeChannels (PopupConfigurationWindow* window, Array<SpikeChannel*> spikeChannelsToRemove, Array<int> indeces)
9798
{
9899
SpikeDetector* processor = (SpikeDetector*) getProcessor();
99100

100-
DataStream* stream = processor->getDataStream (getCurrentStream());
101-
102-
RemoveSpikeChannels* action = new RemoveSpikeChannels (processor, stream, spikeChannelsToRemove, indeces);
101+
if (auto stream = processor->getDataStream (getCurrentStream()))
102+
{
103+
RemoveSpikeChannels* action = new RemoveSpikeChannels (processor, stream, spikeChannelsToRemove, indeces);
103104

104-
CoreServices::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
105-
CoreServices::getUndoManager()->perform ((UndoableAction*) action);
105+
CoreServices::getUndoManager()->beginNewTransaction ("Disabled during acquisition");
106+
CoreServices::getUndoManager()->perform ((UndoableAction*) action);
106107

107-
if (window != nullptr)
108-
window->update (processor->getSpikeChannelsForStream (getCurrentStream()));
108+
if (window != nullptr)
109+
window->update (processor->getSpikeChannelsForStream (getCurrentStream()));
110+
}
109111
}
110112

111113
int SpikeDetectorEditor::getNumChannelsForCurrentStream()

Source/Processors/GenericProcessor/GenericProcessor.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ void GenericProcessor::addTtlLineParameter (
539539
}
540540

541541
void GenericProcessor::parameterChangeRequest (Parameter* param)
542-
{
542+
{
543543
currentParameter = param;
544544

545545
setParameter (-1, 0.0f);
@@ -1622,7 +1622,10 @@ const SpikeChannel* GenericProcessor::getSpikeChannel (uint16 processorId, uint1
16221622

16231623
DataStream* GenericProcessor::getDataStream (uint16 streamId) const
16241624
{
1625-
return dataStreamMap.at (streamId);
1625+
if (dataStreamMap.find (streamId) != dataStreamMap.end())
1626+
return dataStreamMap.at (streamId);
1627+
else
1628+
return nullptr;
16261629
}
16271630

16281631
DataStream* GenericProcessor::getDataStream (String streamKey) const

0 commit comments

Comments
 (0)