Charts icon indicating copy to clipboard operation
Charts copied to clipboard

LineChartRenderer.drawHighlighted crash

Open abbottkilroy opened this issue 11 months ago • 2 comments

What did you do?

We've been seeing A LOT of crashes reported in LineChartRenderer.drawHighlighted.

What did you expect to happen?

No crashes

What happened instead?

It crashes. We've finally got a stack trace that is the probable cause (invalid index in getting lineData[high.dataSetIndex]). We've been unable to reproduce this "on demand".

DGCharts Environment

DGCharts 5.0.0 Xcode version: 15.2 Platform(s) running DGCharts: iOS

Screenshot 2024-03-04 at 11 55 51 AM

abbottkilroy avatar Mar 04 '24 17:03 abbottkilroy

Same here. DGCharts 5.1.0 Lots of crash reports but I cannot reproduce it.

EXC_BREAKPOINT 0x0000000102cb0b54
Crashed: com.apple.main-thread
0  DGCharts                       0x84b54 $s8DGCharts17LineChartRendererC15drawHighlighted7context7indicesySo12CGContextRefa_SayAA9HighlightCGtF + 1336
1  DGCharts                       0x84c20 $s8DGCharts17LineChartRendererC15drawHighlighted7context7indicesySo12CGContextRefa_SayAA9HighlightCGtFTo + 88
2  DGCharts                       0x242fc $s8DGCharts20BarLineChartViewBaseC4drawyySo6CGRectVF + 2116
3  DGCharts                       0x246fc $s8DGCharts20BarLineChartViewBaseC4drawyySo6CGRectVFTo + 64

y2ducky avatar Apr 08 '24 04:04 y2ducky

I've found a workaround that seems to solve the issue. The solution involves calling chartView.highlightValues(nil) every time the chartView's data is changed. This approach seems to prevent crashes by ensuring that any previous highlight indices are cleared before attempting to use them again, which could be the source of the error. Here's an example of how to apply this workaround:

lineChartView.data = newData
lineChartView.highlightValues(nil) // Added line
...
lineChartView.highlightValue(highlight)

I came across this solution by referencing a similar issue discussed here: https://github.com/ChartsOrg/Charts/issues/4024. It appears that the crashes may be related to attempts to use highlight indices from previous data sets, and resetting the highlight values upon data update prevents this issue.

y2ducky avatar Apr 08 '24 06:04 y2ducky