From 1654642fdb0eaaaf6c43871bf3c5f39314dab203 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Fri, 11 Oct 2024 13:16:04 +0100 Subject: [PATCH] HeatMap: Catch memory allocation failures when adding data to the chart and disable it. For #2083 --- plugins/channelrx/heatmap/heatmapgui.cpp | 36 +++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/plugins/channelrx/heatmap/heatmapgui.cpp b/plugins/channelrx/heatmap/heatmapgui.cpp index 6d9fc72138..22411a7ca2 100644 --- a/plugins/channelrx/heatmap/heatmapgui.cpp +++ b/plugins/channelrx/heatmap/heatmapgui.cpp @@ -1506,21 +1506,29 @@ void HeatMapGUI::addToPowerSeries(QDateTime dateTime, double average, double pul { if (m_powerAverageSeries) { - qint64 msecs = dateTime.toMSecsSinceEpoch(); - if (!std::isnan(average)) { - m_powerAverageSeries->append(msecs, average); - } - if (!std::isnan(pulseAverage)) { - m_powerPulseAverageSeries->append(msecs, pulseAverage); - } - if (!std::isnan(max)) { - m_powerMaxPeakSeries->append(msecs, max); - } - if (!std::isnan(min)) { - m_powerMinPeakSeries->append(msecs, min); + try + { + qint64 msecs = dateTime.toMSecsSinceEpoch(); + if (!std::isnan(average)) { + m_powerAverageSeries->append(msecs, average); + } + if (!std::isnan(pulseAverage)) { + m_powerPulseAverageSeries->append(msecs, pulseAverage); + } + if (!std::isnan(max)) { + m_powerMaxPeakSeries->append(msecs, max); + } + if (!std::isnan(min)) { + m_powerMinPeakSeries->append(msecs, min); + } + if (!std::isnan(pathLoss)) { + m_powerPathLossSeries->append(msecs, pathLoss); + } } - if (!std::isnan(pathLoss)) { - m_powerPathLossSeries->append(msecs, pathLoss); + catch (std::bad_alloc&) + { + QMessageBox::critical(this, "Heat Map", QString("Failed to allocate memory for chart series")); + ui->displayChart->setChecked(false); } } }