Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when calling func highlightValue(x: Double, dataSetIndex: Int, callDelegate: Bool) #2840

Closed
everlof opened this issue Oct 3, 2017 · 5 comments

Comments

@everlof
Copy link

everlof commented Oct 3, 2017

I use charts version 3.0.2.

I call highlightValue like this:
highlightValue(x: 2, dataSetIndex: 0, callDelegate: true).

I then get a crash here:
screen shot 2017-10-03 at 09 08 42

When following the code stack trace from the crash:

Stack trace step 5:
Row 522 in ChartViewBase.swift
The Highlight object is created with x=2, y=Nan, dataSetIndex=0 .

Step trace step 4:
The Highlight object is then passed to entryForHighlight on row 547 in ChartViewBase.swift.

Then it crashes with Index out of range on row 278 in CombinedChartData:
let data = dataObjects[highlight.dataIndex]

Because highlight.dataIndex is -1, since it's not set from the constructor. The constructor that is used is:

    /// - parameter x: the x-value of the highlighted value
    /// - parameter y: the y-value of the highlighted value
    /// - parameter dataSetIndex: the index of the DataSet the highlighted value belongs to
    public init(x: Double, y: Double, dataSetIndex: Int)
    {
        _x = x
        _y = y
        _dataSetIndex = dataSetIndex
    }

Where highlight.dataIndex is not initialized.

@liuxuan30
Copy link
Member

You can pass dataIndex to

@objc open func highlightValue(_ highlight: Highlight?, callDelegate: Bool)

Before that you create the highlight object you need to calculate dataIndex carefully when you manually call it.

@liuxuan30
Copy link
Member

Or we add a new method to pass dataIndex into.

@liuxuan30 liuxuan30 reopened this Oct 8, 2017
liuxuan30 added a commit to liuxuan30/Charts that referenced this issue Oct 8, 2017
liuxuan30 added a commit to liuxuan30/Charts that referenced this issue Oct 8, 2017
@everlof
Copy link
Author

everlof commented Oct 8, 2017

Not sure how this is an enhancement, when calling a public API (highlightValue) causes a crash.

However, seems like the fixes you've created would solve it.

@everlof everlof closed this as completed Oct 12, 2017
@liuxuan30
Copy link
Member

@everlof because you use the wrong API as they don't have dataIndex setup. Use @objc open func highlightValue(_ highlight: Highlight?, callDelegate: Bool) and manually create the highlight object and setup your correct dataIndex first.

@jjatie
Copy link
Collaborator

jjatie commented Jan 12, 2018

@liuxuan30 I agree. This sounds like a problem with documentation more than anything else, but your #2852 also works ; )

@ChartsOrg ChartsOrg locked as resolved and limited conversation to collaborators Jan 12, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants