Bug 320 : using serial library before size() causes crash
Last modified: 2006-04-12 04:05




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

 

Reporter:
SimianLogic
Assigned To:
fry

Attachment Type Created Size Actions

Description:   Opened: 2006-04-11 23:25
(Processing 0095, Windows XP)

The following code caused a crash:

//////////////////////////////////////////////////////////////
import processing.serial.*;

Serial myPort;

void setup() {
size(400,400,P3D); //kept in for debugging
myPort = new Serial(this, Serial.list()[2], 9600);
size(400,400,P3D);
}
//////////////////////////////////////////////////////////////
The error is a simple java.lang.ArrayIndexOutOfBoundsException, but of more
interest is the output of the println() function above:

Devel Library
=========================================
Native lib Version = RXTX-2.1-7pre17
Java lib Version = RXTX-2.1-7pre17
COM1 <----expected
COM3 <----expected
COM5 <----expected, and claimed by MyPort
COM1 <----still free, no error
COM3 <----still free, no error

And then the array out of bounds error. It seems as if a call to size after the Serial
Port is initialized causes the error. It works just fine with a normal size(400,400), but
the addition of P3D seems to be doing at least part of the setup() routine over again.

Placing the size(400,400,P3D) above the Serial initialization solved the problem, but
I thought I'd report it in case anyone else ran into this.
Additional Comment #1 From fry 2006-04-12 04:05
this is a bug in your code. as stated in the second line of the reference, size() must be the first
thing in setup().