Skip to content

Fatal error: Index out of range when rendering RadarChartView with accessibility labels #5239

@llYunall

Description

@llYunall

When using RadarChartView (version 5.1.0) and enabling accessibility support, the chart’s internal renderer attempts to read from its accessibilityAxisLabelValueTuples array at an index that doesn’t exist, triggering a Swift “Index out of range” crash:

Thread 1: Fatal error: Index out of range
Swift/ContiguousArrayBuffer.swift:690
let accessibilityLabel = accessibilityAxisLabelValueTuples[j].0

This happens in RadarChartRenderer.drawDataSet(context:dataSet:index:), where the code assumes that the tuples array always has one entry per slice. In fact, under certain data configurations (for example, when custom accessibility entry labels are not provided or the chart has been redrawn), accessibilityAxisLabelValueTuples can be shorter than the number of data points, and no bounds check is performed before subscripting.

Expected Behavior:
The renderer should guard against out-of-bounds access. Possible fixes include:

Before subscripting, check j < accessibilityAxisLabelValueTuples.count;
Or, initialize accessibilityAxisLabelValueTuples in sync with the number of slices;
Or, fall back to a default label/value when no tuple exists for that index.
Environment:

Charts version: 5.1.0 (via CocoaPods / SPM / Carthage)
Xcode: 15.3
iOS SDK: iOS 18.4
Please let me know if you need any additional information or a minimal sample project. Thanks for maintaining Charts!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions