forked from upstream-mirrors/OpenTracks
Fixed another bug reported by users (division by zero).
The issue was most likely related to a race condition (selectedTrackId can change in the UI thread, while the track is being processed in the handler thread). Simulated slow drawing by adding 50ms, works pretty cool :)
This commit is contained in:
@@ -1023,15 +1023,16 @@ public class MyTracksMap extends MapActivity
|
|||||||
loadSelectedTrack();
|
loadSelectedTrack();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Keep a copy of selectedTrackId, because it can change asynchronously.
|
||||||
|
long currentSelectedTrackId = selectedTrackId;
|
||||||
long lastStoredLocationId =
|
long lastStoredLocationId =
|
||||||
providerUtils.getLastLocationId(selectedTrackId);
|
providerUtils.getLastLocationId(currentSelectedTrackId);
|
||||||
int samplingFrequency = -1;
|
int samplingFrequency = -1;
|
||||||
Location location = new Location("");
|
Location location = new Location("");
|
||||||
for (;;) {
|
while (currentSelectedTrackId == selectedTrackId) {
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
cursor = providerUtils.getLocationsCursor(selectedTrackId,
|
cursor = providerUtils.getLocationsCursor(currentSelectedTrackId,
|
||||||
lastSeenLocationId + 1, TRACKPOINT_BUFFER_SIZE, false);
|
lastSeenLocationId + 1, TRACKPOINT_BUFFER_SIZE, false);
|
||||||
if (cursor == null || !cursor.moveToFirst()) {
|
if (cursor == null || !cursor.moveToFirst()) {
|
||||||
// No (more) data
|
// No (more) data
|
||||||
@@ -1053,6 +1054,14 @@ public class MyTracksMap extends MapActivity
|
|||||||
long numTotalPoints = lastStoredLocationId - firstSeenLocationId;
|
long numTotalPoints = lastStoredLocationId - firstSeenLocationId;
|
||||||
samplingFrequency = (int) (1 + numTotalPoints
|
samplingFrequency = (int) (1 + numTotalPoints
|
||||||
/ MyTracksConstants.TARGET_DISPLAYED_TRACK_POINTS);
|
/ MyTracksConstants.TARGET_DISPLAYED_TRACK_POINTS);
|
||||||
|
// TODO: This shouldn't happen after adding currentSelectedTrackId,
|
||||||
|
// but just to be safe until we have 100% confidence.
|
||||||
|
if (samplingFrequency <= 0) {
|
||||||
|
Log.w(MyTracksConstants.TAG,
|
||||||
|
"readAllNewTrackPoints: samplingFreq <= 0, numTotalPoints = "
|
||||||
|
+ numTotalPoints + ", trackId = " + currentSelectedTrackId);
|
||||||
|
samplingFrequency = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
providerUtils.fillLocation(cursor, location);
|
providerUtils.fillLocation(cursor, location);
|
||||||
@@ -1069,7 +1078,8 @@ public class MyTracksMap extends MapActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
numPoints++;
|
numPoints++;
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext() &&
|
||||||
|
currentSelectedTrackId == selectedTrackId);
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user