halfhp / androidplot

Charts and plots for Android
http://androidplot.com
Apache License 2.0
505 stars 159 forks source link

Random crashes due to PixelUtils.init(Context) #106

Closed cheskos closed 3 years ago

cheskos commented 3 years ago

Hi.

I made a small change plot.setDomainStep(StepMode.SUBDIVIDE, mySize); to plot.setDomainStep(StepMode.INCREMENT_BY_VAL, mySize);

on an already working section of code and am wondering why I'm getting crashes out of a sudden due to PixelUtils.init() not being called. How does that work? When should I do it on my own and when should I expect the library to do it? I apologize if this question doesn't belong here and should be in SO instead but it's not really a How-to since the plot was working fine previously

Thank you for your time and for writing this library.

cheskos commented 3 years ago

Turns out another change I did was removing

someFormatter.getLinePaint().setStrokeWidth(PixelUtils.dpToPix(5));

but had never had to call the init method on my own. Could this be a bug?

halfhp commented 3 years ago

Basically, operations that depend on the screen size/density must occur after PixelUtils has been initialized with a context. Unlikely this is a bug that you are seeing but more of an issue of when/where you are calling

someFormatter.getLinePaint().setStrokeWidth(PixelUtils.dpToPix(5));.

Manually initializing PixelUtils is a perfectly acceptable solution.