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>
This commit is contained in:
Dirk Hohndel 2021-08-15 10:05:59 -07:00
parent 75fdb8676b
commit f7e222718a
2 changed files with 6 additions and 1 deletions

View file

@ -1,3 +1,4 @@
- avoid potential crash when switching divelogs
- add GPS fix downloaded from a dive comuter to existing dive site - add GPS fix downloaded from a dive comuter to existing dive site
- fix broken curser left/right shortcut for showing multiple dive computers - fix broken curser left/right shortcut for showing multiple dive computers
- allow editing the profile for dives imported without samples (via CSV) - allow editing the profile for dives imported without samples (via CSV)

View file

@ -1078,7 +1078,11 @@ void ProfileWidget2::setEmptyState()
hideAll(allPercentages); hideAll(allPercentages);
hideAll(handles); hideAll(handles);
#endif #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); hideAll(gases);
} }