We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › can't auto format
Pages: 1 2 
can't auto format (Read 1716 times)
can't auto format
Jan 21st, 2010, 11:56am
 
I can't auto format in one of my projects.
In the line where "Done Saving." etc shows up shows the number 20
Before it also showed 1024 for example.

Is there a way to fix or is it just a processing limit?

Quote:
java.lang.ArrayIndexOutOfBoundsException: 20
     at processing.app.tools.AutoFormat.run(AutoFormat.java:867)
     at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:633)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296
)
     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201
)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
java.lang.ArrayIndexOutOfBoundsException: 20
     at processing.app.tools.AutoFormat.run(AutoFormat.java:867)
     at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
     at java.awt.EventQueue.dispatchEvent(EventQueue.java:633)
     at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296
)
     at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
     at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201
)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
     at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
     at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Re: can't auto format
Reply #1 - Jan 21st, 2010, 3:29pm
 
Hard to say from that info; I've had issues with autoformat that went away after I retyped a class definition or restarted P5.  I've come to view autoformat as a kind of black magic.  Might be something simple to spot, if you're ok pasting code?
Re: can't auto format
Reply #2 - Jan 22nd, 2010, 1:41am
 
I also think it's hard to say where the trouble is, unless you post some code.
Quote:
java.lang.ArrayIndexOutOfBoundsException: 20

This says that there is something like "int[] myInt= new int[20]", which means that you create an array from myInt[0] to myInt[19]. Somewhere you then try to put a variable in myInt[20], which doesn't exist.
Re: can't auto format
Reply #3 - Jan 22nd, 2010, 2:35am
 
timm, the error is in the auto format code in Processing (PDE) itself! Smiley

I recall some threads complaining about this feature, how it fails on large projects.
Perhaps you can copy & paste code by units (functions, classes) in a new Processing editor, auto format it, then paste it back in the project.
Re: can't auto format
Reply #4 - Jan 22nd, 2010, 4:25am
 
Just get into the habit of writing clean code from the start - then you won't have to rely on black magic Tongue
Re: can't auto format
Reply #5 - Jan 22nd, 2010, 4:48am
 
Too true, blindfish, actually I think I never used this feature... although sometime I should, when I try some code posted here!  Tongue
It might seem a chore to properly indent and align, distracting from the flow of creativity... But sometime, slower is better, forcing you to think on your code...
And after a while of using discipline, it becomes so natural it just a background task...
Re: can't auto format
Reply #6 - Jan 25th, 2010, 8:25am
 
The problem is in this piece of code:
They only way to fix is to delete around 4 if rules which is no option.
Must i report it as a processing bug?

Code:
if(checkPos(x-1, y-1, z) == true){//z
if(checkPos(x-1, y, z) == true){
if(checkPos(x-1, y+1, z) == true){
if(checkPos(x, y-1, z) == true){
if(checkPos(x, y+1, z) == true){
if(checkPos(x+1, y-1, z) == true){
if(checkPos(x+1, y, z) == true){
if(checkPos(x+1, y+1, z) == true){
if(checkPos(x, y, z-1) == true){//z-1
if(checkPos(x-1, y, z-1) == true){
if(checkPos(x-1, y+1, z-1) == true){
if(checkPos(x, y-1, z-1) == true){
if(checkPos(x, y+1, z-1) == true){
if(checkPos(x+1, y-1, z-1) == true){
if(checkPos(x+1, y, z-1) == true){
if(checkPos(x+1, y+1, z-1) == true){
if(checkPos(x, y, z-1) == true){//z+1
if(checkPos(x-1, y, z+1) == true){
if(checkPos(x-1, y+1, z+1) == true){
if(checkPos(x, y-1, z+1) == true){
if(checkPos(x, y+1, z+1) == true){
if(checkPos(x+1, y-1, z+1) == true){
if(checkPos(x+1, y, z+1) == true){
if(checkPos(x+1, y+1, z+1) == true){
mVolume = append(mVolume, i);
c++;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}


And
Re: can't auto format
Reply #7 - Jan 25th, 2010, 9:12am
 
Why don't you just push some of them back? It does not matter in terms of errors or anything, it is purely a visual (and thus helpful in debugging) thing ...
Re: can't auto format
Reply #8 - Jan 25th, 2010, 9:21am
 
Wow, this looks almost like ASCII art...

this:
Code:
if(checkPos(x-1, y-1, z) == true) 



could be written as this:
Code:
if(checkPos(x-1, y-1, z)) 




and this:
Code:
if(checkPos(x-1, y-1, z)){
if(checkPos(x-1, y-1, z)){
//something
}
}


is equivalent to: (some brackets are removed)
Code:
if(checkPos(x-1, y-1, z))
if(checkPos(x-1, y-1, z)){
//something
}


but you could also write:
Code:
if(checkPos(x-1, y-1, z) && checkPos(x-1, y-1, z)){
//something
}


You may also find a way to use for loops instead.
Re: can't auto format
Reply #9 - Jan 25th, 2010, 9:32am
 
Shocked I look at that code and think: there must be a better way!

I've no idea what you're doing in checkPos(), but I get the impression that it might be better to check whether each separate axis coordinate is within the desired range rather than running all those separate if statements...

And if nothing else combine them logically with && (and also don't bother with '== true', it's not necessary to test for truth on a boolean). e.g.:

Code:
// Z
// x-1
if(checkPos(x-1, y-1, z) && checkPos(x-1, y, z) && checkPos(x-1, y+1, z)){
 // x (strange - no test for x,y,z?)
 if(checkPos(x, y-1, z) && checkPos(x, y+1, z)){
 // x+1
 if(checkPos(x+1, y-1, z) && checkPos(x+1, y, z) && checkPos(x+1, y+1, z) ){
   // Z-1 etc...

   }
 }
}


That will certainly be a little more readable, though as suggested before the answer to the original question is not to rely on auto-formatting!
Re: can't auto format
Reply #10 - Jan 25th, 2010, 10:57am
 
thx all,

based on the x y z below, can i make a for loop of that?
The one i made now for z is a endless loop..


Code:
	if(g[i] == true){
ct++;
x = i % w;
y = (i / w) % h;
z = i / (w * h);

for (z = z-1; z < z+3; z++){
println(z);
}
}
Re: can't auto format
Reply #11 - Jan 25th, 2010, 11:48am
 
Code:
boolean mySuperTest(int x, int y, int z){

   for(int i=-1; i<=1; i++)
 for(int j=-1; j<=j; j++)
for(int k=-1; k<=1; k++)
   if(!checkPos(x+i, y+j, z+k))
 return false;

   return true;
}
Re: can't auto format
Reply #12 - Jan 25th, 2010, 1:00pm
 
clankill3r wrote on Jan 25th, 2010, 10:57am:
The one i made now for z is a endless loop..

for (z = z-1; z < z+3; z++){


because z will always be less than z + 3. use a different name for the loop variable (i usually use 'i')
Re: can't auto format
Reply #13 - Jan 25th, 2010, 4:39pm
 
Thx gll

your code works great (exept  j<=j; which i didn't spotted first Smiley ).
Re: can't auto format
Reply #14 - Jan 25th, 2010, 4:53pm
 
Honestly, it was the same for me with (z < z+3;).
It's just difficult to focus.

Yo may use w,h,d as argument as well to control the radius:
Code:
boolean mySuperTest(int x, int y, int z){

   for(int i=-w; i<=w; i++)
 for(int j=-h; j<=h; j++)
for(int k=-d; k<=d; k++)
   if(!checkPos(x+i, y+j, z+k))
 return false;

   return true;
}
Pages: 1 2