summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2021-08-15 10:05:59 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-08-16 18:37:59 -0700
commitf7e222718a6677912094c1994c1681bed5171b28 (patch)
tree9e2a599febd0532aa3bb1299a063fecf479f179d
parent75fdb8676bdc24a232351c207ea4cdd2e9caeb22 (diff)
downloadsubsurface-f7e222718a6677912094c1994c1681bed5171b28.tar.gz
desktop: avoid crash when changing dive logs
If the last displayed dive had events, those DiveEventItems had slots connected that would update those icons if things changed. When closing the dive log and switching to a different one, those slots were still called and would then access freed memory (the event structure from that old dive that is long gone by then). This code explicitly deletes those DiveEventItems which also removes those signal slot connections. Fixes #3305 Sugested-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--CHANGELOG.md1
-rw-r--r--profile-widget/profilewidget2.cpp6
2 files changed, 6 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 939dc2ea2..e6b10ea08 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,4 @@
+- avoid potential crash when switching divelogs
- add GPS fix downloaded from a dive comuter to existing dive site
- fix broken curser left/right shortcut for showing multiple dive computers
- allow editing the profile for dives imported without samples (via CSV)
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 55a00a8e8..e296a8b9b 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -1078,7 +1078,11 @@ void ProfileWidget2::setEmptyState()
hideAll(allPercentages);
hideAll(handles);
#endif
- hideAll(eventItems);
+ // the events will have connected slots which can fire after
+ // the dive and its data have been deleted - so explictly delete
+ // the DiveEventItems
+ qDeleteAll(eventItems);
+ eventItems.clear();
hideAll(gases);
}