From 894cbcc4e7f9aa04c1c6e96d49efdcfcce86969d Mon Sep 17 00:00:00 2001 From: Mark Liversedge Date: Thu, 30 May 2013 19:31:26 +0100 Subject: [PATCH] Fix first file SEGV If you delete and readd an activity after showing it on the diary view you get a SEGV. This is an edge case related to deleting the last activity and going back to the blank state before importing another. Actually there are 3 technical issues; 1. GcCalendar doesn't get notified by MainWindow when there are no rides -- so it crashes on refresh 2. RideSummaryWindow doesn't get notified by home window if its not visible 3. RideSummaryWindow should check rideItem isn't NULL before trying to plot zones (but only for date range summaries) Fixes #622 --- src/GcCalendar.cpp | 7 +++++++ src/HomeWindow.cpp | 3 ++- src/MainWindow.cpp | 6 ++++-- src/RideSummaryWindow.cpp | 6 +++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/GcCalendar.cpp b/src/GcCalendar.cpp index 25ab2b204..efd3834ee 100644 --- a/src/GcCalendar.cpp +++ b/src/GcCalendar.cpp @@ -951,6 +951,13 @@ GcMultiCalendar::setRide(RideItem *ride) if (active) return; if (!isVisible()) { stale = true; + + // notify of ride gone though as not repeated + if (!_ride) { + for (int i=0; isetRide(_ride); // current ride is on this one + } + } return; } diff --git a/src/HomeWindow.cpp b/src/HomeWindow.cpp index c12d761f7..84ef408ec 100644 --- a/src/HomeWindow.cpp +++ b/src/HomeWindow.cpp @@ -239,7 +239,8 @@ HomeWindow::titleChanged() void HomeWindow::rideSelected() { - if (amVisible()) { + // we need to notify of null rides immediately + if (!myRideItem || amVisible()) { for (int i=0; i < charts.count(); i++) { // show if its not a tab diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 0f5857262..574e2f868 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -1249,13 +1249,13 @@ MainWindow::rideTreeWidgetSelectionChanged() // update the ride property on all widgets // to let them know they need to replot new // selected ride + gcCalendar->setRide(ride); + gcMultiCalendar->setRide(ride); _rideMetadata->setProperty("ride", QVariant::fromValue(dynamic_cast(ride))); analWindow->setProperty("ride", QVariant::fromValue(dynamic_cast(ride))); homeWindow->setProperty("ride", QVariant::fromValue(dynamic_cast(ride))); diaryWindow->setProperty("ride", QVariant::fromValue(dynamic_cast(ride))); trainWindow->setProperty("ride", QVariant::fromValue(dynamic_cast(ride))); - gcCalendar->setRide(ride); - gcMultiCalendar->setRide(ride); if (!ride) return; @@ -1990,6 +1990,8 @@ MainWindow::removeCurrentRide() if (allRides->childCount() == 0) { ride = NULL; rideTreeWidgetSelectionChanged(); // notifies children + gcCalendar->setRide(ride); // and the pesky calendars + gcMultiCalendar->setRide(ride); } treeWidget->setCurrentItem(itemToSelect); diff --git a/src/RideSummaryWindow.cpp b/src/RideSummaryWindow.cpp index 0775b86e1..0f4e31cdb 100644 --- a/src/RideSummaryWindow.cpp +++ b/src/RideSummaryWindow.cpp @@ -186,7 +186,7 @@ RideSummaryWindow::htmlSummary() const RideFile *ride; if (!rideItem && !ridesummary) return ""; // nothing selected! - else ride = rideItem->ride(); + else ride = rideItem ? rideItem->ride() : NULL; if (!ride && !ridesummary) return ""; // didn't parse! @@ -381,7 +381,7 @@ RideSummaryWindow::htmlSummary() const // // Time In Zones // - if (rideItem->numZones() > 0) { + if (rideItem && rideItem->numZones() > 0) { QVector time_in_zone(rideItem->numZones()); for (int i = 0; i < rideItem->numZones(); ++i) { @@ -396,7 +396,7 @@ RideSummaryWindow::htmlSummary() const // // Time In Zones HR // - if (rideItem->numHrZones() > 0) { + if (rideItem && rideItem->numHrZones() > 0) { QVector time_in_zone(rideItem->numHrZones()); for (int i = 0; i < rideItem->numHrZones(); ++i) {