hochileo / achartengine

Automatically exported from code.google.com/p/achartengine
0 stars 0 forks source link

When running an asynctask and adding negative values to series.add, it throws an IllegalArgumentException #314

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I've attached a sample Android studios project to simplify this description. 

I created a new XYSeriesRenderer, and on a background thread I'm adding values 
to the series and showing a preview. 
like so: series.add(x[i], values[i]);, where -50 <= x <= 50, and -2500 <= 
values <= 2500. (values = x^2) and interval of 0.1.

I occasionally get this thrown:
 java.lang.IllegalArgumentException: -49.9 > -61.39999999999945
Full logcat attached.

Note: there are a couple things that make this more complicated. This is a 
timing issue. Reducing the values to -5 <= x <= 5, and -25 <= values <= 25, 
will not run into this issue. Also, debugging this also avoids the issue.

Second thing is, if you add a positive value first, you won't run into this 
issue. It's only if you run negative values first that don't get processed fast 
enough.

Please provide a source code snippet that we can use to replicate the issue.
See attached. I've added the full project, the MainActivity file and layout. 
Use whatever is easiest.

What version of the product binary library are you using?
1.2.0

Other comments:
When running the application, you have two buttons.
1. Runs the negative values. Occasionally this works, and if it does then force 
close the application (or swipe away in the recent apps list). It should 
eventually crash.

2. Runs positive values only from 0 < x < 50, and 0 < values < 2500.
Run this once, and then you can run 1 as many times as you like. 

Original issue reported on code.google.com by ydin...@gmail.com on 7 Jun 2013 at 11:30

Attachments:

GoogleCodeExporter commented 9 years ago
I've narrowed it down to line 301 of XYSeries.java

// this would be simply: end = mXY.higherKey(end) but NavigableMap is
      // available since API 9
      // so we have to do this hack in order to support older versions
      SortedMap<Double, Double> tailMap = mXY.tailMap(stop);
      if (!tailMap.isEmpty()) {
        Iterator<Double> tailIterator = tailMap.keySet().iterator();
        Double next = tailIterator.next();
        if (tailIterator.hasNext()) {
          stop = tailIterator.next();
        } else {
          stop += next;
        }
      }

When it does 'stop += next', if stop is negative, it can make it smaller than 
start. 

I have no clue what any of this code does, but I'm hoping that it's possible to 
change the 'else' condition to 'else if stop > 0'.

It works for my test case. A better solution would be to find out why it 
sometimes goes in there, and sometimes it doesn't. 

Original comment by ydin...@gmail.com on 13 Jun 2013 at 11:24

GoogleCodeExporter commented 9 years ago

Original comment by dandrome...@gmail.com on 31 Oct 2013 at 8:16