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

fatal error: Index out of range while subclassing renderer #2446

Closed
bardonadam opened this issue May 17, 2017 · 3 comments
Closed

fatal error: Index out of range while subclassing renderer #2446

bardonadam opened this issue May 17, 2017 · 3 comments

Comments

@bardonadam
Copy link

I need to subclass HorizontalBarChartRenderer so that I can change implementation of drawDataSet(...). So I created my custom renderer, but because of access control and because I'm using Cocoapods I had to override little more than just drawDataSet:

  • fileprivate class Buffer
  • fileprivate var _buffers = Buffer
  • fileprivate func prepareBuffer(dataSet: IBarChartDataSet, index: Int)
  • fileprivate var _barShadowRectBuffer: CGRect = CGRect() open override
  • open override func drawDataSet(context: CGContext, dataSet: IBarChartDataSet, index: Int)

I didn't change anything yet, above methods were just copied from HorizontalBarChartRenderer, and I set the renderer like this:
self.horizontalBarView.renderer = CustomRenderer(dataProvider: self.horizontalBarView, animator: self.horizontalBarView.chartAnimator, viewPortHandler: self.horizontalBarView.viewPortHandler).

When I try to run it, I get fatal error: Index out of range at BarCharRenderer's drawValues():
let buffer = _buffers[dataSetIndex]

When I tried to set renderer to standard HorizontalBarChartRenderer the same way:
self.horizontalBarView.renderer = HorizontalBarChartRenderer(dataProvider: self.horizontalBarView, animator: self.horizontalBarView.chartAnimator, viewPortHandler: self.horizontalBarView.viewPortHandler)

everything works fine. Am I missing something?

@liuxuan30
Copy link
Member

from your footprints your _buffers[dataSetIndex] is not correctly initialized, check from there.

@bardonadam
Copy link
Author

Yes, that is correct. But I don't get it why. If my CustomRenderer is basically just a copy of HorizontalBarChartRenderer(I haven't changed the implementation of the methods that I've overridden), so I'd assume that if HorizontalBarChartRenderer works, then changing it to CustomRenderer at the same place should work as well.

@bardonadam
Copy link
Author

I finally know what was the issue, my subclass didn't override drawValues() method, as it wasn't explicit that it is needed. Moreover, this method is accessing variable shouldDrawValues which is internal and therefor can't be accessed outside the module. I commented out the part where it's used for now, but I'll have to somehow mimic it on my own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants