Page 1 of 1

ArrayIndexOutOfBoundsException when clearing/adding data

Posted: Fri Nov 09, 2007 10:22 am
by 9345036
Hello,

here is a simple program which - unfortunately - crashes TChart.

The problem occurred, when we wanted to show data, which is continually changing. As new data became available, we updated the TChart by:
series.clear(); // erase old data
series.add(...); // draw new data
Sometimes, this led to an ArrayIndexOutOfBoundsException.

I have condensed the problem to the example program below. The delay
(in doTest()) is inessential. It just assures a more certain crash. Without it, the crash occurs less frequently.
Also, using refreshControl(), does not improve things. Instead of an ArrayIndexOutOfBoundsException, a NullPointerException is thrown in this case.


>>>>>>>>>>>>>>>>>>> Begin Program <<<<<<<<<<<<<<<<

import java.awt.Frame;
import com.steema.teechart.TChart;
import java.awt.BorderLayout;
import com.steema.teechart.styles.FastLine;

public class AWTTest extends Frame {

private static final long serialVersionUID = 1L;
private TChart tChart = null;
private FastLine series;
private short data[];


public static void main(String[] args) {
new AWTTest();
}

public AWTTest() {
super();
initialize();
setVisible(true);
doTest();
}

private void initialize() {
this.setSize(600, 400);
this.setTitle("Frame");

tChart = new TChart();
this.add(tChart, BorderLayout.CENTER);
series = new FastLine(tChart.getChart());

data = new short[4000];
for (int i = 0; i < data.length; ++i) {
data = (short)(16000.0*Math.sin(i*0.232));
}
}

private void addSeries() {
for (int i = 0; i < data.length; ++i) {
series.add(data);
}
}

private void delay(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {}
}

private void doTest() {
for (int i = 0; i < 10; ++i) {
series.clear();
// tChart.refreshControl();
delay(100);
addSeries();
// tChart.refreshControl();
delay(100);
}
}
}


>>>>>>>>>>>>>>>>>>> End Program <<<<<<<<<<<<<<<<<

_________________
Best Regards

Thomas

Posted: Tue Nov 13, 2007 10:30 am
by Marc
Hello Thomas,

We've re-run your test code, increasing cycles too, and haven't been able to generate the failure. Could you confirm please that you're using the latest build version, Build 1.0.1.825.

Regards,
Marc Meumann

Posted: Tue Nov 13, 2007 11:12 am
by 9345036
Marc wrote:Could you confirm please that you're using the latest build version, Build 1.0.1.825.
Yes, I downloaded it some days ago and I'd used it before I opened the thread. I send you the example as a small jar File. It was built with Eclipse 3.2 and crashes reliable on our machine:
Win XP Pro. We tried JRE 1.4 / 1.5 / 1.6. No difference.

Posted: Tue Nov 13, 2007 2:49 pm
by narcis
Hi Thomas,

I haven't found the project you mention. Where did you send it?

Thanks in advance!

Posted: Tue Nov 13, 2007 3:07 pm
by 9345036
narcis wrote:I haven't found the project you mention. Where did you send it?
Sent it to info@steema.com

Posted: Wed Nov 14, 2007 2:44 pm
by Marc
Hello,

The program you sent runs but doesn't close (looking at your code in the previous post that's by design, not a problem). Your example runs ok when tested on Win2003 and on WinXP. The XP machine was previously unprepared and the JRE 5 (1.5) runtime environment was installed.

Have you tried your application on different machines?

Regards,
Marc

Posted: Thu Nov 15, 2007 9:44 am
by 9345036
Marc wrote:Have you tried your application on different machines?
Now I've tried it. The problem occurs on a dual core machine. It doesn't occur on a second single core machine. Have you tested it on a dual core PC?

I run the test program from a shell. If no messages are thrown all is fine. If there are problems, messages appear in the shell.

And yes, it was the first AWT app we'd written. Perhaps the Window Close message isn't processed in a right way, therefore the window can't be closed properly.

Posted: Thu Nov 15, 2007 10:51 am
by Marc
Hello,

Yes, the Win2003 test machine is Core 2 Duo. The XP machine is Dual Core (Pentium D).

Do you have any more information on the error messages thrown? An option to get a clearer location on the error might be to unwrap the TeeChart Jar to source and debug it as part of the project source.

Re. AWT App close.
Yes, we added the following to the example code to close our own test copy of your project:

Code: Select all

addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent e) { dispose();}
    });
Regards,
Marc

Posted: Thu Nov 15, 2007 1:09 pm
by 9345036
Marc wrote:Hello,


Do you have any more information on the error messages thrown? An option to get a clearer location on the error might be to unwrap the TeeChart Jar to source and debug it as part of the project source.


Regards,
Marc
Hello Marc,

here is the error message:

>>>>>>>>>>>>>>>> Begin Message<<<<<<<<<<<<<<<<<<
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 214
at com.steema.teechart.styles.FastLine.calcPosition(FastLine.java:208)
at com.steema.teechart.styles.FastLine.drawValue(FastLine.java:246)
at com.steema.teechart.styles.FastLine.draw(FastLine.java:228)
at com.steema.teechart.styles.Series.drawSeries(Series.java:2222)
at com.steema.teechart.Chart.internalDraw(Chart.java:670)
at com.steema.teechart.Chart.paint(Chart.java:1807)
at com.steema.teechart.TChart.paintComponent(TChart.java:568)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1164
at com.steema.teechart.styles.ValueList.calcStats(ValueList.java:314)
at com.steema.teechart.styles.ValueList.getMaximum(ValueList.java:357)
at com.steema.teechart.styles.Series.getMaxYValue(Series.java:3719)
at com.steema.teechart.Chart.internalMinMax(Chart.java:1584)
at com.steema.teechart.axis.Axis.calcMinMax(Axis.java:1122)
at com.steema.teechart.axis.Axis.adjustMaxMin(Axis.java:355)
at com.steema.teechart.axis.Axes.adjustMaxMin(Axes.java:235)
at com.steema.teechart.Chart.calcAxisRect(Chart.java:1927)
at com.steema.teechart.Chart.internalDraw(Chart.java:630)
at com.steema.teechart.Chart.paint(Chart.java:1807)
at com.steema.teechart.TChart.paintComponent(TChart.java:568)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
>>>>>>>>>>>>> End Message <<<<<<<<<<<<<<<<<<<<<<

Due to the loop, the error message appears several times (with a different index number each time).

Posted: Mon Nov 19, 2007 2:23 pm
by 9345036
We have less exceptions, if AutoRepaint is set to false. However, zooming and panning seems to be disabled now.

Anything else, we can contribute to find the reason for the exceptions?

Posted: Tue Nov 20, 2007 4:53 pm
by Marc
Hello,

We've not been able to provoke the error over several different types of tests. Were you able to run with the TeeChart source to debug the problem directly there? Does it continue to be just one machine affected?

Regards,
Marc