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 › drawing lines: 'exceeds the code limit' Error
Page Index Toggle Pages: 1
drawing lines: 'exceeds the code limit' Error (Read 869 times)
drawing lines: 'exceeds the code limit' Error
Mar 9th, 2006, 5:29pm
 
Hello All,

When I try to draw very long lines (several thousand vertices) or when I draw several thousand short lines, I get the following error:

/tmp/build28588.tmp/Temporary_820_8030.java:1:325:2770:1: Semantic Error: Method "void draw();" in type "Temporary_820_8030" produced a code attribute that exceeds the code limit of 65535 elements.

The draw function I use is basically this:

void draw() {
beginShape (LINE_STRIP) ; vertex ( 129,  775) ; vertex ( 129,  750) ; endShape () ;
beginShape (LINE_STRIP) ; vertex ( 129,  805) ; vertex ( 129,  748) ; endShape () ;
}

(...yet I either have several thousand more shapes, or have a few shapes with several thousand vertices.)

Is there any way to draw a large number of lines or to draw very long lines without obtaining this error? (I do not need the image to be continuously redrawn as there is no development or motion)

Thanks very much!

Michael

Re: drawing lines: 'exceeds the code limit' Error
Reply #1 - Mar 9th, 2006, 5:41pm
 
Google matches for that error are thin on the ground, but this cache link seems to give a hint.

Are you storing all your coordinates inside the source code  Apparently there is a limit on the size of a Java class file (or possibly a method in a class file, I'm not sure) that means that sometimes this just isn't practical.

You might have luck storing the coordinates in a text file and loading them at run time.  If you're not sure how to do that, post back and I'll see if I can find some example code.
Re: drawing lines: 'exceeds the code limit' Error
Reply #2 - Mar 9th, 2006, 5:47pm
 
You might also have luck using LINES instead of lots of separate line strips.

Your example code:

Code:

void draw() {  
 beginShape(LINE_STRIP);
 vertex(129, 775);
 vertex(129, 750);
 endShape();  
 beginShape(LINE_STRIP);
 vertex(129, 805);
 vertex(129, 748);
 endShape();  
}


Is the same as:

Code:

void draw() {  
 beginShape(LINES);
 vertex(129, 775);
 vertex(129, 750);
 vertex(129, 805);
 vertex(129, 748);
 endShape();  
}



Which is basically the same as:

Code:

void draw() {  
 line(129, 775, 129, 750);
 line(129, 805, 129, 748);
}

Re: drawing lines: 'exceeds the code limit' Error
Reply #3 - Mar 9th, 2006, 6:07pm
 
this is the same as this issue:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1140882603
or this guy:
http://processing.org/discourse/yabb/YaBB.cgi?board=Programs;action=display;num=1107292834

you should load all the vertex information from a file and then use a for() loop to iterate through the array of data, rather than including all of it in the draw method. also, if you're just drawing a single line, you can use the line() command instead of beginShape(), or as TomC notes, use beginShape(LINES), followed by several calls to vertex(), then endShape().
Re: drawing lines: 'exceeds the code limit' Error
Reply #4 - Mar 9th, 2006, 6:37pm
 
Thank you very much for your responses.

Tried using the simpler "lines' command, yet this produces the same error once I get beyond about 5000 lines.

So I'll try loading the vertex information from a text file instead.

TomC, in case you have a sample file that shows how to read and segment info from a text file, I'd really appreciate it.

Thanks again!


Re: drawing lines: 'exceeds the code limit' Error
Reply #5 - Mar 9th, 2006, 7:19pm
 
Briefly, for a text file points.txt which contains no blank lines, and looks something like:

Code:

129 775
129 750
129 805
129 748


Then something like...

Code:


// arrays for x and y
int[] x;
int[] y;

void setup() {
size(150,900);
String[] lines = loadStrings("points.txt");
x = new int[lines.length];
y = new int[lines.length];
for (int i = 0; i < lines.length; i++) {
int[] coords = int(split(lines[i]));
x[i] = coords[0];
y[i] = coords[1];
}
}

void draw() {
background(255);
stroke(0);
beginShape(LINES);
for (int i = 0; i < x.length; i++) {
vertex(x[i],y[i]);
}
endShape();
}



...should do the trick. Untested with large files, so may have silly errors.  

Your mileage may vary for float coordinates, unreliable text files, line loops, stroke weights, colours, 3D, etc.

Look up the definitions of loadStrings(), split() and int() in the reference to see what's going on.
Page Index Toggle Pages: 1