ChartsOrg / ChartsOrg/Charts

LineChartRenderer drawHighlighted(context: CGContext, indices: [Highlight]) crash

Open
#4,960 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

## What did you do?

[presumably] Using `Lihe chart view` with live updates user taps chart view

## What did you expect to happen?

"Highlighted" line to y axis is displayed on chart view

## What happened instead?

App crashes on `guard let set = lineData[high.dataSetIndex] as? LineChartDataSetProtocol` with "index out of range" exception

## Charts Environment

Charts (4.1.0)
Xcode v.14.0.1
Swift 5
Platform: iOS
macOS v.12.5.1

## Demo Project

Wasn't able to reproduce the crash myself, just received crash reports from Firebase Crashlytics and through XCode reports.
Reproduce rate: [presumably] low, 6 events during first week after release
Crash Log example:
`Date/Time: 2022-10-16 20:48:11.7358 -0500
Launch Time: 2022-10-16 20:43:46.4317 -0500
OS Version: iPhone OS 15.6.1 (19G82)
Release Type: User
Baseband Version: 1.70.01
Report Version: 104

Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000010151ecb4
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Terminating Process: exc handler [72164]

Triggered by Thread: 0

Kernel Triage:
VM - pmap_enter failed with resource shortage

Thread 0 name:
Thread 0 Crashed:
0 Charts 0x000000010151ecb4 Swift runtime failure: Index out of range + 0 (:0)
1 Charts 0x000000010151ecb4 specialized _ArrayBuffer._checkInoutAndNativeTypeCheckedBounds(_:wasNativeTypeChecked:) + 4 (:0)
2 Charts 0x000000010151ecb4 specialized Array._checkSubscript(_:wasNativeTypeChecked:) + 4 (:0)
3 Charts 0x000000010151ecb4 specialized Array.subscript.getter + 4 (ChartData.swift:452)
4 Charts 0x000000010151ecb4 ChartData.subscript.getter + 4 (:0)
5 Charts 0x000000010151ecb4 LineChartRenderer.drawHighlighted(context:indices:) + 1312
6 Charts 0x000000010151e8f8 ChartData.subscript.getter + 4 (ChartData.swift:452)
7 Charts 0x000000010151e8f8 LineChartRenderer.drawHighlighted(context:indices:) + 356 (LineChartRenderer.swift:763)
8 Charts 0x000000010151ed94 @objc LineChartRenderer.drawHighlighted(context:indices:) + 108 (:0)
9 Charts 0x00000001014c1908 BarLineChartViewBase.draw(_:) + 2116 (BarLineChartViewBase.swift:251)
10 Charts 0x00000001014c1d0c @objc BarLineChartViewBase.draw(_:) + 68 (:0)
11 UIKitCore 0x000000018a4290b4 -[UIView(CALayerDelegate) drawLayer:inContext:] + 608 (UIView.m:18154)
12 QuartzCore 0x000000018bbb4564 CABackingStoreUpdate_ + 192 (CABackingStore.cpp:1319)
13 QuartzCore 0x000000018bbf809c ___ZN2CA5Layer8display_Ev_block_invoke + 64 (CALayer.mm:9538)
14 QuartzCore 0x000000018bbf9b9c -[CALayer _display] + 1912 (CALayer.mm:9536)
15 QuartzCore 0x000000018bb98d7c CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 420 (CALayer.mm:2447)
16 QuartzCore 0x000000018bbad5b4 CA::Context::commit_transaction(CA::Transaction*, double, double*) + 452 (CAContextInternal.mm:2612)
17 QuartzCore 0x000000018bbb64a8 CA::Transaction::commit() + 704 (CATransactionInternal.mm:449)
18 QuartzCore 0x000000018bb983a0 CA::Transaction::flush_as_runloop_observer(bool) + 88 (CATransactionInternal.mm:956)
19 UIKitCore 0x000000018a7e06e0 _UIApplicationFlushCATransaction + 72 (UIApplication.m:0)
20 UIKitCore 0x000000018aa7ad5c _UIUpdateSequenceRun + 84 (_UIUpdateSequence.mm:112)
21 UIKitCore 0x000000018b101edc schedulerStepScheduledMainSection + 144 (_UIUpdateScheduler.m:778)
22 UIKitCore 0x000000018b1016a4 runloopSourceCallback + 92 (_UIUpdateScheduler.m:870)
23 CoreFoundation 0x0000000187edf414 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28 (CFRunLoop.c:1972)
24 CoreFoundation 0x0000000187ef01a0 __CFRunLoopDoSource0 + 208 (CFRunLoop.c:2016)
25 CoreFoundation 0x0000000187e29694 __CFRunLoopDoSources0 + 268 (CFRunLoop.c:2053)
26 CoreFoundation 0x0000000187e2f05c __CFRunLoopRun + 828 (CFRunLoop.c:2951)
27 CoreFoundation 0x0000000187e42bc8 CFRunLoopRunSpecific + 600 (CFRunLoop.c:3268)
28 GraphicsServices 0x00000001a3fae374 GSEventRunModal + 164 (GSEvent.c:2200)
29 UIKitCore 0x000000018a7b6b58 -[UIApplication _run] + 1100 (UIApplication.m:3511)
30 UIKitCore 0x000000018a538090 UIApplicationMain + 364 (UIApplication.m:5064)
31 Lightspeed 0x000000010031ca70 main + 176 (main.swift:11)
32 dyld 0x000000010077dda4 start + 520 (dyldMain.cpp:879)`

Contributor guide

Open the contributing guide

Research direction

Start with LineChartRenderer.swift:763 and the drawHighlighted(context:indices:) call path, then inspect ChartData.swift:452 where the out-of-range subscript occurs. Use the supplied crash trace to understand how the highlight dataset index can exceed the available data sets; done means the highlighted chart no longer crashes for that state, with regression coverage if the project has a suitable test location.

Written by the indexing model from the issue text.

Assessment

Tech stack
ios, swift
Domain
mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.