Bug 563 : array out of bounds error, appearing most of the times
Last modified: 2007-06-01 15:59




Status:
RESOLVED
Resolution:
DUPLICATE of bug 341
Priority:
P2
Severity:
normal

 

Reporter:
marvel123
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2007-05-26 04:22
I started using Processing last year (thank you everybody!) At the time I
was using Windows XP. After switching over to UBUNTU 6.10, later to UBUNTU
7.4, the error started happening.

My hardware is a BenQ laptop with a Centrino processor.

I refer to bug 369 for a similar story, after many tries it sometimes
shoots through and the program is executed.

However, many of the circumstances in this case are different, so I chose
to open a new bug report. I stripped my code to produce the shortest
possible fragment to reproduce the bug. Please find it at the bottom of
this note. The program will not do anything when it executes alright, it is
the minimum amount of code leading to the error and nothing else. The error
used to occur in sub2(), but when I started stripping code it moved to
sub1(), this is why I added sub2(). Initially testArray, sub1 and sub2 were
on seperate tabs, but it also produces an error when it is on a single tab.

As you see I had some fun with it, and the line where it goes wrong
indicates that the width value is recognised correctly, but the height
value is 'overestimated' in sub1().

The fact that it happens sometimes in the original program, but most of the
time in the test program, seems to say something about timing, when does
the routine pick up the width and height value. But then, why only an error
in the height value?

My wild guess is something in the direction of thread execution timing, I
hope you have enough information to straighten this out, if I can be of
help in any way please let me know

greetings, marvel123


/**
*
* by Marvel123

testArray

sometimes java.lang.ArrayIndexOutOfBoundsException:
comes like in bug 369
testsketch to generate error
*/

float[][] test; //
int maxX,maxY;

void setup()
{

maxX = 1020; // screen size 1020x690
maxY = 690; //

size(maxX, maxY);
//test
test = new float[width*height][3];
}

void draw()
{
sub1();
}

void sub1()
{
if (maxY < height){
if (maxX < width){
for (int i=0;i<width*height;i++){
test[i][0] = random(100);
}
}
else if (maxX == width){
for (int i=0;i<width*height;i++){
test[i][0] = random(100); //here it stops in Ubuntu Feisty
}
}
else{
for (int i=0;i<width*height;i++){
test[i][0] = random(100);
}
}
}
else if (maxY == height){
if (maxX < width){
for (int i=0;i<width*height;i++){
test[i][0] = random(100);
}
}
else if (maxX == width){
for (int i=0;i<width*height;i++){
test[i][0] = random(100);
}
}
else{
for (int i=0;i<width*height;i++){
test[i][0] = random(100);
}
}
}
else{
if (maxX < width){
for (int i=0;i<width*height;i++){
test[i][0] = random(100);
}
}
else if (maxX == width){
for (int i=0;i<width*height;i++){
test[i][0] = random(100);
}
}
else{
for (int i=0;i<width*height;i++){
test[i][0] = random(100);
}
}
}
sub2();
}



void sub2(){
float bottomLev = test[0][0];
float topLev = test[0][0];
if (maxY >= height){
for (int i=1;i<width*height;i++){
if (test[i][0] > topLev){
topLev = test[i][0];
}
if (test[i][0] < bottomLev){
bottomLev = test[i][0];
}
}
}
else{
for (int i=1;i<width*height;i++){
if (test[i][0] > topLev){
topLev = test[i][0];
}
if (test[i][0] < bottomLev){
bottomLev = test[i][0];
}
}
}
}
Additional Comment #1 From marvel123 2007-05-26 11:12
here is also the complete error message:

java.lang.ArrayIndexOutOfBoundsException: 703800
at Temporary_3095_9032.sub1(Temporary_3095_9032.java:41)
at Temporary_3095_9032.draw(Temporary_3095_9032.java:28)
at processing.core.PApplet.handleDisplay(PApplet.java:1355)
at processing.core.PGraphics.requestDisplay(PGraphics.java:564)
at processing.core.PApplet.run(PApplet.java:1450)
at java.lang.Thread.run(Unknown Source)
Additional Comment #2 From marvel123 2007-05-28 14:27
if it helps to solve the bug, or if someone needs to circumvene the bug,I
have a crude workaround, turn the methods from void to boolean if possible,
and check the height:

/**
*
* by Marvel123
*
* testArray2
*
* sometimes java.lang.ArrayIndexOutOfBoundsException:
* comes like in bug 369
* testsketch to test work-around
*/


..the same....



void setup()
{
........
}

void draw()
{
sub1();
//just some code to have something happen:
ellipse(width/2,height/2,height/3,height/3);
noLoop();
}

boolean sub1()
//void sub1()

{
if (height>maxY){
return false;
}
......the same.....
return true;
}

void sub2(){
......the same (!)...
}
Additional Comment #3 From fry 2007-06-01 15:59
i think you're running into bug #341, which is specific to linux.

*** This bug has been marked as a duplicate of 341 ***