diff --git a/oscar/Graphs/gLineChart.cpp b/oscar/Graphs/gLineChart.cpp index 19ee86f5..751691bf 100644 --- a/oscar/Graphs/gLineChart.cpp +++ b/oscar/Graphs/gLineChart.cpp @@ -116,7 +116,9 @@ void gLineChart::SetDay(Day *d) Session *sess = d->sessions[i]; if (!sess->enabled()) continue; - CPAPMode mode = (CPAPMode)sess->settings[CPAP_Mode].toInt(); + // Don't use operator[] here or else it will insert a default-constructed entry + // into sess->settings if it's not present. + CPAPMode mode = (CPAPMode)sess->settings.value(CPAP_Mode).toInt(); if (mode >= MODE_BILEVEL_FIXED) { m_enabled[CPAP_Pressure] = true; // probably a confusion of Pressure and IPAP somewhere diff --git a/oscar/SleepLib/day.cpp b/oscar/SleepLib/day.cpp index bc386795..6f140f96 100644 --- a/oscar/SleepLib/day.cpp +++ b/oscar/SleepLib/day.cpp @@ -304,10 +304,17 @@ EventDataType Day::settings_wavg(ChannelID code) double s0 = 0, s1 = 0, s2 = 0, tmp; for (auto & sess : sessions) { - if (sess->enabled() && sess->type() == MT_CPAP) { + if (sess->enabled()) { auto set = sess->settings.find(code); if (set != sess->settings.end()) { + if (code == CPAP_Mode && sess->type() != MT_CPAP) { + // There used to be a bug in gLineChart::SetDay that inserted a CPAP_Mode + // setting in any session that didn't already have one. That shouldn't + // happen any more, but leave this diagnostic message here in case it does. + qWarning() << sess->session() << "non-CPAP session with CPAP mode setting"; + continue; + } s0 = sess->hours(); tmp = set.value().toDouble(); s1 += tmp * s0;