Bug 331 : loadPixels limits the pixels[] array to strange numbers, causes Out of Bounds exception
Last modified: 2007-02-03 09:57




Status:
RESOLVED
Resolution:
INVALID -
Priority:
P2
Severity:
normal

 

Reporter:
nilloc
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2006-04-24 14:16
When using loadPixels to create the pixels[] array, the size of the array
is limited. Strangely, the limiting number is not constant, though 10,000
is common.
For example, I load a picture into a 700 x 700 window, then call
loadPixels(). Then I have println() tell me pixels.length and it says that
it is 10,000, but it should be 700*700, which is 490000. Changing the size
of the window doesn't fix it.
Occasionally, I have gotten programs to work using loadPixels and accessing
the full range of the of the array, but most frequently, I get an
OutOfBoundsException when it hits 10000 (or 40000, which has also been the
limiting number a few times).

Below is a piece of code from the program I've been using to work through
this problem. It is a stupid program, but it creates the error.
Obviously, you will have to create an image called me.jpg in order to
recreate the problem. Below the code is the information printed to the
console, including the println() line telling me the size of the pixels[]
array and the error information.

PImage pic;

void setup()
{
size(700, 700);
pic=loadImage("me.jpg");
image (pic, 0, 0);
loadPixels();
println("The size of pixels array = " + pixels.length);
}

void draw()
{

for(int u=0; u<(width/2*height/2); u++)
{
pixels[u]=0;
}

}


========================================================

The size of pixels array = 10000


java.lang.ArrayIndexOutOfBoundsException: 10000
at Temporary_3249_8721.draw(Temporary_3249_8721.java:34)
at processing.core.PApplet.display(PApplet.java:1326)
at processing.core.PGraphics.requestDisplay(PGraphics.java:520)
at processing.core.PApplet.run(PApplet.java:1142)
at java.lang.Thread.run(Unknown Source)

java.lang.ArrayIndexOutOfBoundsException: 10000

at Temporary_3249_8721.draw(Temporary_3249_8721.java:34)

at processing.core.PApplet.display(PApplet.java:1326)

at processing.core.PGraphics.requestDisplay(PGraphics.java:520)

at processing.core.PApplet.run(PApplet.java:1142)

at java.lang.Thread.run(Unknown Source)
=================================================
thanks.
Additional Comment #1 From nilloc 2006-05-01 12:39
After submitting this report, I did figure out that exported executables do
work, even if it won't work while running in Processing.
Additional Comment #2 From fry 2006-05-12 10:23
i can't replicate this bug, can you provide more details about your machine
and setup? can you replicate this on any other machines?