From 621ab0535cfea4bce714d7d44456849877cac2f6 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 18 Jun 2019 15:17:14 +0200 Subject: [PATCH] Fix a crash when a graphview is updated with the very first value --- libnymea-app-core/models/logsmodelng.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libnymea-app-core/models/logsmodelng.cpp b/libnymea-app-core/models/logsmodelng.cpp index 4a7fb5f5..c030ab52 100644 --- a/libnymea-app-core/models/logsmodelng.cpp +++ b/libnymea-app-core/models/logsmodelng.cpp @@ -396,9 +396,11 @@ void LogsModelNg::newLogEntryReceived(const QVariantMap &data) m_graphSeries->removePoints(0, 2); } - // Prevent triangles, add a point right before the new one which reflects the old value - qreal previousValue = m_graphSeries->points().at(0).y(); - m_graphSeries->insert(0, QPointF(entry->timestamp().addMSecs(-1).toMSecsSinceEpoch(), previousValue)); + // Prevent triangles, add a point right before the new one which reflects the old value (if there is one) + if (m_graphSeries->points().count() > 0) { + qreal previousValue = m_graphSeries->points().at(0).y(); + m_graphSeries->insert(0, QPointF(entry->timestamp().addMSecs(-1).toMSecsSinceEpoch(), previousValue)); + } // Add the actual value m_graphSeries->insert(0, QPointF(entry->timestamp().toMSecsSinceEpoch(), entry->value().toBool() ? 1 : 0));