From f20eae182a7e4af7069114707aca47b120a86a68 Mon Sep 17 00:00:00 2001 From: bparks13 Date: Mon, 4 Aug 2025 14:29:16 -0400 Subject: [PATCH] Check if canvas exists before accessing it - Give a warning to the user if the canvas does not exist, as this will heavily impact functionality --- Source/OnixSourceEditor.cpp | 21 +++++++++++++++++++++ Source/OnixSourceEditor.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/Source/OnixSourceEditor.cpp b/Source/OnixSourceEditor.cpp index 5aed8d2..bb52270 100644 --- a/Source/OnixSourceEditor.cpp +++ b/Source/OnixSourceEditor.cpp @@ -416,6 +416,12 @@ void OnixSourceEditor::comboBoxChanged(ComboBox* cb) void OnixSourceEditor::updateComboBox(ComboBox* cb) { + if (canvas == nullptr) + { + Onix1::showWarningMessageBoxAsync("Missing Canvas", missingCanvasErrorMessage); + return; + } + bool isPortA = cb == headstageComboBoxA.get(); PortName currentPort = isPortA ? PortName::PortA : PortName::PortB; @@ -432,6 +438,7 @@ void OnixSourceEditor::updateComboBox(ComboBox* cb) std::string headstage = isPortA ? headstageComboBoxA->getText().toStdString() : headstageComboBoxB->getText().toStdString(); source->updateDiscoveryParameters(currentPort, PortController::getHeadstageDiscoveryParameters(headstage)); + canvas->addHub(headstage, PortController::getPortOffset(currentPort)); if (headstage == NEUROPIXELSV2E_HEADSTAGE_NAME || headstage == NEUROPIXELSV1E_HEADSTAGE_NAME) @@ -631,6 +638,12 @@ void OnixSourceEditor::setComboBoxSelection(ComboBox* comboBox, std::string head void OnixSourceEditor::refreshComboBoxSelection() { + if (canvas == nullptr) + { + Onix1::showWarningMessageBoxAsync("Missing Canvas", missingCanvasErrorMessage); + return; + } + Array hubTabs = canvas->getHubTabs(); bool resetPortA = true, resetPortB = true; @@ -657,6 +670,12 @@ void OnixSourceEditor::refreshComboBoxSelection() OnixDeviceMap OnixSourceEditor::createTabMapFromCanvas() { + if (canvas == nullptr) + { + Onix1::showWarningMessageBoxAsync("Missing Canvas", missingCanvasErrorMessage); + return OnixDeviceMap{}; + } + return canvas->getSelectedDevices(canvas->settingsInterfaces); } @@ -675,6 +694,8 @@ void OnixSourceEditor::saveVisualizerEditorParameters(XmlElement* xml) void OnixSourceEditor::loadVisualizerEditorParameters(XmlElement* xml) { + checkForCanvas(); + LOGD("Loading OnixSourceEditor settings."); if (xml->hasAttribute("headstagePortA")) diff --git a/Source/OnixSourceEditor.h b/Source/OnixSourceEditor.h index 1cdc134..c7a717b 100644 --- a/Source/OnixSourceEditor.h +++ b/Source/OnixSourceEditor.h @@ -137,6 +137,8 @@ namespace OnixSourcePlugin static constexpr int DefaultBlockReadSize = 4096; + 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."; + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(OnixSourceEditor); }; }