Skip to content

Commit 7b181e4

Browse files
authored
Merge pull request #140 from open-ephys-plugins/issue-139
Check if canvas exists before accessing it
2 parents 8de7fef + f20eae1 commit 7b181e4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Source/OnixSourceEditor.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,12 @@ void OnixSourceEditor::comboBoxChanged(ComboBox* cb)
416416

417417
void OnixSourceEditor::updateComboBox(ComboBox* cb)
418418
{
419+
if (canvas == nullptr)
420+
{
421+
Onix1::showWarningMessageBoxAsync("Missing Canvas", missingCanvasErrorMessage);
422+
return;
423+
}
424+
419425
bool isPortA = cb == headstageComboBoxA.get();
420426

421427
PortName currentPort = isPortA ? PortName::PortA : PortName::PortB;
@@ -432,6 +438,7 @@ void OnixSourceEditor::updateComboBox(ComboBox* cb)
432438
std::string headstage = isPortA ? headstageComboBoxA->getText().toStdString() : headstageComboBoxB->getText().toStdString();
433439

434440
source->updateDiscoveryParameters(currentPort, PortController::getHeadstageDiscoveryParameters(headstage));
441+
435442
canvas->addHub(headstage, PortController::getPortOffset(currentPort));
436443

437444
if (headstage == NEUROPIXELSV2E_HEADSTAGE_NAME || headstage == NEUROPIXELSV1E_HEADSTAGE_NAME)
@@ -631,6 +638,12 @@ void OnixSourceEditor::setComboBoxSelection(ComboBox* comboBox, std::string head
631638

632639
void OnixSourceEditor::refreshComboBoxSelection()
633640
{
641+
if (canvas == nullptr)
642+
{
643+
Onix1::showWarningMessageBoxAsync("Missing Canvas", missingCanvasErrorMessage);
644+
return;
645+
}
646+
634647
Array<CustomTabComponent*> hubTabs = canvas->getHubTabs();
635648

636649
bool resetPortA = true, resetPortB = true;
@@ -657,6 +670,12 @@ void OnixSourceEditor::refreshComboBoxSelection()
657670

658671
OnixDeviceMap OnixSourceEditor::createTabMapFromCanvas()
659672
{
673+
if (canvas == nullptr)
674+
{
675+
Onix1::showWarningMessageBoxAsync("Missing Canvas", missingCanvasErrorMessage);
676+
return OnixDeviceMap{};
677+
}
678+
660679
return canvas->getSelectedDevices(canvas->settingsInterfaces);
661680
}
662681

@@ -675,6 +694,8 @@ void OnixSourceEditor::saveVisualizerEditorParameters(XmlElement* xml)
675694

676695
void OnixSourceEditor::loadVisualizerEditorParameters(XmlElement* xml)
677696
{
697+
checkForCanvas();
698+
678699
LOGD("Loading OnixSourceEditor settings.");
679700

680701
if (xml->hasAttribute("headstagePortA"))

Source/OnixSourceEditor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ namespace OnixSourcePlugin
137137

138138
static constexpr int DefaultBlockReadSize = 4096;
139139

140+
static constexpr char* missingCanvasErrorMessage = "The canvas for this plugin could not be found. Some functionality may not work as expected, and you may not be able to acquire or record data. Try removing and replacing the plugin.";
141+
140142
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OnixSourceEditor);
141143
};
142144
}

0 commit comments

Comments
 (0)