Skip to content

Commit

Permalink
fix an issue where switching charts back and forth can crash the app
Browse files Browse the repository at this point in the history
  • Loading branch information
grobolom committed Jan 24, 2025
1 parent e0e299f commit 4214c28
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/de/dennisguse/opentracks/chart/ChartView.java
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,18 @@ private record TitleDimensions(
*/
private void drawSeriesTitles(Canvas canvas) {
Iterator<TitlePosition> tpI = titleDimensions.titlePositions.iterator();

for (ChartValueSeries chartValueSeries : seriesList) {
if (chartValueSeries.isEnabled() && chartValueSeries.hasData() || allowIfEmpty(chartValueSeries)) {
String title = getContext().getString(chartValueSeries.getTitleId(unitSystem));
Paint paint = chartValueSeries.getTitlePaint();

// It is possible for the titlePositions to become empty temporarily, while switching between
// chart screens quickly.
if (!tpI.hasNext()) {
return;
}

TitlePosition tp = tpI.next();
int y = topBorder - spacer - (titleDimensions.lineCount - tp.line) * (titleDimensions.lineHeight + spacer);
canvas.drawText(title, tp.xPos + getScrollX(), y, paint);
Expand Down

0 comments on commit 4214c28

Please sign in to comment.