Skip to content

Commit a3f9eaa

Browse files
committed
fix for macos scatterplot crash
1 parent d3c0ede commit a3f9eaa

File tree

5 files changed

+81
-0
lines changed

5 files changed

+81
-0
lines changed

src/ColoringAction.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,29 @@ ColoringAction::ColoringAction(QObject* parent, const QString& title) :
159159
_scatterplotPlugin->getScatterplotWidget().setColoringMode(ScatterplotWidget::ColoringMode::Constant);
160160
}
161161

162+
ColoringAction::~ColoringAction()
163+
{
164+
// Disconnect all connections to prevent accessing freed memory during destruction
165+
if (_scatterplotPlugin) {
166+
disconnect(&_scatterplotPlugin->getPositionDataset(), nullptr, this, nullptr);
167+
disconnect(&_scatterplotPlugin->getPositionSourceDataset(), nullptr, this, nullptr);
168+
disconnect(&_scatterplotPlugin->getScatterplotWidget(), nullptr, this, nullptr);
169+
}
170+
171+
// Disconnect child action connections
172+
disconnect(&_colorByAction, nullptr, this, nullptr);
173+
disconnect(&_colorByModel, nullptr, this, nullptr);
174+
disconnect(&_dimensionAction, nullptr, this, nullptr);
175+
disconnect(&_constantColorAction, nullptr, this, nullptr);
176+
disconnect(&_colorMap1DAction, nullptr, this, nullptr);
177+
disconnect(&_colorMap2DAction, nullptr, this, nullptr);
178+
179+
// Disconnect current dataset if valid
180+
if (_currentColorPointsDataset.isValid()) {
181+
disconnect(&_currentColorPointsDataset, nullptr, this, nullptr);
182+
}
183+
}
184+
162185
QMenu* ColoringAction::getContextMenu(QWidget* parent /*= nullptr*/)
163186
{
164187
auto menu = new QMenu("Color", parent);

src/ColoringAction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ class ColoringAction : public VerticalGroupAction
3535
* @param title Title
3636
*/
3737
Q_INVOKABLE ColoringAction(QObject* parent, const QString& title);
38+
39+
/**
40+
* Destructor - ensures proper cleanup of Qt connections
41+
*/
42+
~ColoringAction();
3843

3944
/**
4045
* Get the context menu for the action

src/ScatterplotPlugin.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,29 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
270270

271271
ScatterplotPlugin::~ScatterplotPlugin()
272272
{
273+
// Ensure proper cleanup order - disconnect any remaining connections
274+
// before member variables are destroyed
275+
if (_scatterPlotWidget) {
276+
disconnect(_scatterPlotWidget, nullptr, this, nullptr);
277+
disconnect(&_scatterPlotWidget->getPixelSelectionTool(), nullptr, this, nullptr);
278+
}
279+
280+
// Clear any remaining connections from position dataset
281+
if (_positionDataset.isValid()) {
282+
disconnect(&_positionDataset, nullptr, this, nullptr);
283+
}
284+
285+
// Disconnect all connections from settings action members to avoid
286+
// accessing freed memory during member destruction
287+
disconnect(&_settingsAction, nullptr, this, nullptr);
288+
disconnect(&_settingsAction.getColoringAction(), nullptr, this, nullptr);
289+
disconnect(&_settingsAction.getColoringAction().getColorByAction(), nullptr, this, nullptr);
290+
disconnect(&_settingsAction.getPlotAction().getPointPlotAction().getFocusSelection(), nullptr, this, nullptr);
291+
disconnect(&_settingsAction.getPlotAction().getPointPlotAction().getSizeAction(), nullptr, this, nullptr);
292+
disconnect(&_settingsAction.getPlotAction().getPointPlotAction().getOpacityAction(), nullptr, this, nullptr);
293+
294+
// Disconnect from sampler action
295+
disconnect(&getSamplerAction(), nullptr, this, nullptr);
273296
}
274297

275298
void ScatterplotPlugin::init()
@@ -972,6 +995,9 @@ void ScatterplotPlugin::updateSelection()
972995

973996
void ScatterplotPlugin::updateHeadsUpDisplay()
974997
{
998+
#ifdef __APPLE__
999+
return;
1000+
#endif
9751001
getHeadsUpDisplayAction().removeAllHeadsUpDisplayItems();
9761002

9771003
if (_positionDataset.isValid()) {

src/SettingsAction.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@ SettingsAction::SettingsAction(QObject* parent, const QString& title) :
4545
connect(&_scatterplotPlugin->getPositionDataset(), &Dataset<Points>::changed, this, updateEnabled);
4646
}
4747

48+
SettingsAction::~SettingsAction()
49+
{
50+
// Disconnect all connections to prevent accessing freed memory during destruction
51+
if (_scatterplotPlugin) {
52+
disconnect(&_scatterplotPlugin->getPositionDataset(), nullptr, this, nullptr);
53+
disconnect(&_scatterplotPlugin->getPositionSourceDataset(), nullptr, this, nullptr);
54+
disconnect(&_scatterplotPlugin->getScatterplotWidget(), nullptr, this, nullptr);
55+
}
56+
57+
// Disconnect all child actions to prevent cross-references during destruction
58+
disconnect(&_coloringAction, nullptr, this, nullptr);
59+
disconnect(&_plotAction, nullptr, this, nullptr);
60+
disconnect(&_positionAction, nullptr, this, nullptr);
61+
disconnect(&_renderModeAction, nullptr, this, nullptr);
62+
disconnect(&_selectionAction, nullptr, this, nullptr);
63+
disconnect(&_subsetAction, nullptr, this, nullptr);
64+
disconnect(&_clusteringAction, nullptr, this, nullptr);
65+
disconnect(&_exportAction, nullptr, this, nullptr);
66+
disconnect(&_miscellaneousAction, nullptr, this, nullptr);
67+
disconnect(&_datasetsAction, nullptr, this, nullptr);
68+
}
69+
4870
QMenu* SettingsAction::getContextMenu()
4971
{
5072
auto menu = new QMenu();

src/SettingsAction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class SettingsAction : public GroupAction
3434
* @param title Title
3535
*/
3636
Q_INVOKABLE SettingsAction(QObject* parent, const QString& title);
37+
38+
/**
39+
* Destructor - ensures proper cleanup of Qt connections
40+
*/
41+
~SettingsAction();
3742

3843
/**
3944
* Get action context menu

0 commit comments

Comments
 (0)