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 & HelpOther Libraries › oscP5: ArrayIndexOutOfBoundsException
Pages: 1 2 
oscP5: ArrayIndexOutOfBoundsException (Read 4281 times)
oscP5: ArrayIndexOutOfBoundsException
Sep 5th, 2007, 6:59pm
 
Hi,

I've got a strange issue with oscP5 (any version tried).

i'm running Processing 124 or 125 on two networked computers (the first sends datas, the second receives).

I have tried locally (2 processing (124 and 125) running at the same time on the same machine), the problem is the same.

This is the code for the sender

Quote:
import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
OscMessage myMessage = new OscMessage("/Computer1");  
           
void setup() {
          size(100, 100);
          frameRate(25);
          oscP5 = new OscP5(this,12000);
          myRemoteLocation = new NetAddress("192.168.0.2",12001);        
                    }
                       
void draw() {
oscP5.send(myMessage, myRemoteLocation);  
myMessage.add("Hello World");
                 }


and the code for the receiver

Quote:
import oscP5.*;
import netP5.*;

OscP5 oscP5;

void setup() {
 size(100,100);
 frameRate(25);
 oscP5 = new OscP5(this,12001);
}


void oscEvent(OscMessage theOscMessage) {
     if(theOscMessage.checkAddrPattern("/Computer1")==true) {
     String firstValue = theOscMessage.get(0).stringValue();  
     println(firstValue);
 }
}


This is what appears in the receiver computer in its processing's console.

Quote:
Hello World // << repeating for about 3 seconds


And then this error message:

Quote:
### [2007/9/5 4:43:53] ERROR @ UdpServer.run() ArrayIndexOutOfBoundsException:  java.lang.ArrayIndexOutOfBoundsException: 1404


1404 is random.

Repeating until i stop the sender's sketch.

This error appears on the sender computer at the beginning when i start its sketch and keeps repeating until i stop the sketch.

Quote:
### [2007/9/6 1:9:17] ERROR @ UdpClient.send ioexception while sending packet.



This error appears on the receiver computer at the beginning when i start its sketch

Quote:
2007-09-05 04:04:39.903 java[767] CFLog (0): CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port = 0x12b03, name = 'java.ServiceProvider'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2007-09-05 04:04:39.903 java[767] CFLog (99): CFMessagePortCreateLocal(): failed to name Mach port (java.ServiceProvider)


Any idea ? Thank you.


EDIT> i have checked the /usr/include/servers/bootstrap_defs.h for the error codes, this is what i found :

Quote:
#define      BOOTSTRAP_SERVICE_ACTIVE            1103
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #1 - Sep 6th, 2007, 2:53am
 
hi jaylfk,
try to use the code below for your sender.
i put the initialization of your oscMessage into setup, after oscP5 is initialized.
i also put the "Hello World" string into setup, otherwise your oscMessage would just be filled up with this string non stop after each draw update. i tried the code here, works fine. i didnt check in detail where this error originates from, so i guess it has to do with the moment of initializing the OscMessage.

Code:

import oscP5.*;
import netP5.*;

OscP5 oscP5;
NetAddress myRemoteLocation;
OscMessage myMessage;

void setup() {
size(100, 100);
frameRate(25);
oscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress("127.0.0.1",12001);
myMessage = new OscMessage("/Computer1");
myMessage.add("Hello World");
}

void draw() {
oscP5.send(myMessage, myRemoteLocation);
}


the receiving part is fine, you may also try the plug method of oscP5 to get around the parsing in oscEvent e.g.

Code:

import oscP5.*;
import netP5.*;

OscP5 oscP5;

void setup() {
size(100,100);
frameRate(25);
oscP5 = new OscP5(this,12001);
oscP5.plug(this,"incoming","/Computer1");
}


void incoming(String theString) {
println("i got a string, "+theString);
}



regarding the boostrap_register message, this link may give you an answer (this doesnt just apply to eclipse but also any other java app)

andi
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #2 - Sep 6th, 2007, 9:32am
 
Thank you andi for your answer.

The code you posted works well, but how can i refresh/update it ?

I mean, hello world string is just an example.
If i use the same code and put myMessage.add(i); in a loop in draw, it does the same error above mentioned.

e.g Quote:
for (int i=0; i<result; i++)
{
if(i >= result2)
 {
i = i-result2;
myMessage.add(i);
 }
else{
myMessage.add(i);
     }
}


Also for the "bootstrap_register(): failed 1103 (0x44f)" error, i 've found its origin. It happens when i launch 2 processing apps (124 and 125) on the same machine. The first launched processing 124 app is declaring to the bootstrap as "java", so when the second processing 125 app tries, it gets an error feedback from the boostrap register.
It's not important, the sketches are still working anyway.

Smiley
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #3 - Sep 6th, 2007, 12:56pm
 
the bootstrap error is covered in the reference:
http://processing.org/reference/environment/platforms.html#mac
it's an apple bug.
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #4 - Sep 6th, 2007, 6:58pm
 
hi,
short note on the out of bounds error. if you are constantly adding values to an osc message, you are basically increasing the size of the message, which becomes an issue when the message, send as a datagram over the network, is received at the receiver end. the array out of bounds exceptions origins from a datagram oversize at the network socket.
if you need to send big chunks of data via osc, one thing you can do is to increase the datagram size at the receiver side. what does this mean? each integer for examples takes 4 bytes (float for example takes 8 bytes, etc.), so if you want to send 1000 ints, your message will consist of 4000 bytes plus the header bytes, so on the receiver side you need to be able to receive a datagram with a size of at least of 4000 bytes + header bytes. since the default datagram size is 1536 you would need to increase the size. to set the datagram size at the receiver side:

Code:

import oscP5.*;
import netP5.*;

OscP5 oscP5;

void setup() {
size(100,100);
frameRate(25);
OscProperties myProperties = new OscProperties();
// increase the datagram size to 10000 bytes
// by default it is set to 1536 bytes
myProperties.setDatagramSize(10000);
myProperties.setListeningPort(12001);
oscP5 = new OscP5(this,myProperties);
}

// make sure you have a draw() method incuded in your
// sketch, even if it is empty.
void draw() {}


void oscEvent(OscMessage theOscMessage) {
if(theOscMessage.checkAddrPattern("/Computer1")==true) {
String firstValue = theOscMessage.get(0).stringValue();
println(theOscMessage.arguments().length+" / "+firstValue);
}
}




if you want to reset the content of an oscMessage, then currently this does the job:

Code:

void draw() {
myMessage = new OscMessage("/Computer1");
myMessage.add("Hello World");
oscP5.send(myMessage, myRemoteLocation);
}



(re)setting a specific value at a certain position in an oscMessage is not yet supported, but i think i should implement this, so will do.

best,
andi

Re: oscP5: ArrayIndexOutOfBoundsException
Reply #5 - Sep 7th, 2007, 2:50pm
 
Thank you very much !

You made it real clear.
I finally get it to work as i wanted to. Smiley
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #6 - Dec 19th, 2007, 12:17pm
 
Hello guys!

I am having similar problem, thou I am getting the following error: UdpClient.send ioexception while sending packet

I am actually sending an array[][] with floats to SuperCollider and approximately after 2sec I get this error.

Would you please comment, if the problem is hidden in the datagram size or somewhere else ?

All the best!
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #7 - Dec 21st, 2007, 7:14am
 
UdpClient.send ioexception indicates that you are sending OSC messages via the UDP protocol. the error occurs if you try to send too many bytes to a remote machine that is not capable of handling the amount of sent bytes. in this case the server, remote machine, needs to increase its datagram size.
UDP in general is able to handle 64k bytes per packet. an OSC message (excluding address pattern) with 1000 ints would be
1000*4 bytes(ints) + 1000*1 byte (typetag) = 5000 bytes

so in order to receive 1000 ints with e.g. oscP5, the datagramsize, which is 1536 bytes by default for oscP5, would need to be increased to (to be save) 5400 bytes.

how to do that see the oscP5properties example that comes with oscP5, or is available on the website.

the UdpServer.run ArrayOutOfBoundsException occurs for same reasons, increase the datagramsize and you should be fine.

maybe also keep in mind that OSC is considered to be a control message protocol, meaning only values to control something should be transmitted over a network and you should avoid to use the protocol to exchange huge packets of data e.g. sound or video streaming, fft, blob detection. try to make as many calulations inside of an application and only distributed the results that will be explicitly useful on the remote machines. this will keep the network communication efficient and little.

Re: oscP5: ArrayIndexOutOfBoundsException
Reply #8 - Nov 25th, 2009, 9:39pm
 
Sorry to dig this dusty old topic up but i need some help Embarrassed

While experimenting around with oscP5 trying to send data from one sketch (sender) to another (receiver), i get this error on the receiver.

I know the problem is in the for loop of the sender but i haven't found a solution to fix it.

Code:
### [2009/11/25 13:25:14] ERROR @ OscP5 ERROR. an error occured while forwarding an OscMessage
to a method in your program. please check your code for any
possible errors that might occur in the method where incoming
OscMessages are parsed e.g. check for casting errors, possible
nullpointers, array overflows ... .
method in charge : oscEvent  java.lang.reflect.InvocationTargetException



Code:

// Sender

import oscP5.*;
import netP5.*;

NetAddress myRemoteLocation;
NetAddress myRemoteLocation2;    
int x;
float drawX, drawY;          

void setup(){
size(500,500);
frameRate(60);
rectMode(CENTER);
noStroke();
smooth();
myRemoteLocation = new NetAddress("127.0.0.1",12000);
myRemoteLocation2 = new NetAddress("127.0.0.1",12001);
}
 
                       
void draw(){
 
 background(0);
 
 for (int i=0; i<360; i++){
 drawX = sin(radians(i))*200+(width/2);
 drawY = cos(radians(i))*200+(height/2);
 fill(random(10,255),random(10,255),random(10,255));
 ellipse(drawX,drawY,4,4);
 
 OscMessage myOscMessage = new OscMessage("/X");
 OscMessage myOscMessage2 = new OscMessage("/Y");
 myOscMessage.add(drawX);
 myOscMessage2.add(drawY);
 OscP5.flush(myOscMessage,myRemoteLocation);
 OscP5.flush(myOscMessage2,myRemoteLocation2);
 }
}


Code:

// Receiver

import oscP5.*;

OscP5 oscP5X, oscP5Y;
float drawX, drawY;

void setup() {
 size(500,500);
 frameRate(60);
 rectMode(CENTER);
 noStroke();
 oscP5X = new OscP5(this,12000);
 oscP5Y = new OscP5(this,12001);
}

void draw(){
 background(0);
 fill(random(10,255),random(10,255),random(10,255));
 ellipse(drawX,drawY,4,4);
}


void oscEvent(OscMessage theOscMessage) {
 if(theOscMessage.checkAddrPattern("/X")==true) {
 int firstValue = theOscMessage.get(0).intValue();  
 drawX = firstValue;
}
 if(theOscMessage.checkAddrPattern("/Y")==true) {
 int secondValue = theOscMessage.get(0).intValue();  
 drawY = secondValue;
 }
}

Re: oscP5: ArrayIndexOutOfBoundsException
Reply #9 - Nov 26th, 2009, 9:29am
 
Hi again,

I tried this in receiver's setup() but still stuck with the same error.

Quote:
 OscProperties propX = new OscProperties();
 OscProperties propY = new OscProperties();
 propX.setDatagramSize(10000);
 propY.setDatagramSize(10000);
 propX.setListeningPort(5500);
 propY.setListeningPort(5501);
 oscP5X = new OscP5(this,propX);
 oscP5Y = new OscP5(this,propY);


Any idea why it doesn't work ?
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #10 - Nov 26th, 2009, 9:48am
 
Oups! i've just realized that i was sending float from sender to int in receiver.

the correct receiver code must be

Quote:
import oscP5.*;
import netP5.*;

OscP5 oscP5X, oscP5Y;
float drawX, drawY;

void setup() {
 size(500,500);
 frameRate(60);
 rectMode(CENTER);
 noStroke();
 oscP5X = new OscP5(this,5500);
 oscP5Y = new OscP5(this,5501);
}

void draw(){
 background(0);
 fill(random(10,255),random(10,255),random(10,255));
 ellipse(drawX,drawY,4,4);
}


void oscEvent(OscMessage theOscMessage) {
if(theOscMessage.checkAddrPattern("/X")==true) {
float firstValue = theOscMessage.get(0).floatValue();  
drawX = firstValue;
}
if(theOscMessage.checkAddrPattern("/Y")==true) {
float secondValue = theOscMessage.get(0).floatValue();  
drawY = secondValue;
 }
}


Now the problem is that the circle is not correctly drawn in the receiver's sketch.  Huh
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #11 - Nov 27th, 2009, 8:48pm
 
hi, maybe the server/client code below might help.
in your code you create 2 instances of oscP5, each for a different address pattern, listening on different ports. you dont necessarily need to do that, you can only run 1 instance of oscP5 and use the addressPattern as identifier instead of the port - which you are already doing in oscEvent. so no need for 2 instances.
In your sender (client) code you are sending one message for each iteration of your loop which is quite inefficient, rather consider to create an empty osc message before starting the loop, with each iteration of your loop, add a new value to that message, after the loop is finished, send/flush the message.
to receive an array of ints (or floats or Strings) on the server side, use oscP5.plug which will instruct oscP5 to forward incoming messages directly to a dedicated function inside your sketch - instead of going through oscEvent (see Server example below). maybe the client and server code below makes things easier for you. run both sketches at a time and use key 1 and 2 in the client sketch so send a bunch of ints to the server sketch.
best,
andreas

Code:

/**
* OSC server, waiting for incoming messages on port 5500
*/

import oscP5.*;
import netP5.*;
 
OscP5 oscP5;

void setup() {
 size(400,400);
 frameRate(25);
 OscProperties props = new OscProperties();
 // increase the default datagram size used by oscP5
 // because we are receiving a lot of values at a time.
 props.setDatagramSize(4096);
 // set the listening port for oscP5
 props.setListeningPort(5500);
 // initialize oscP5
 oscP5 = new OscP5(this,props);
 
 // use oscP5's plug method to link incoming
 // osc messages with functions included in your sketch.
 // in the following, incoming messages with address pattern
 // /X and /Y will be forwarded to positionX() and positionY()
 oscP5.plug(this, "positionX","/X");
 oscP5.plug(this, "positionY","/Y");
 
 background(0);  
}

// positionX will be called by oscP5 when receiving
// an OSC message with address pattern /X (see plug above)
// the OSC arguments must be of type int
void positionX(int[] theValues) {
 println("X: "+theValues.length);
 for(int i=0;i<theValues.length;i++) {
   stroke(theValues[i]);
   line(0,i,width,i);
 }
}

// positionX will be called by oscP5 when receiving
// an OSC message with address pattern /Y (see plug above)
// the OSC arguments must be of type int

void positionY(int[] theValues) {
 println("Y: "+theValues.length);
 for(int i=0;i<theValues.length;i++) {
   stroke(theValues[i]);
   line(i,0,i,height);
 }
}


void draw() {
}


Code:

/**
* OSC client, sending OSC messages to a server listening on port 5500
*/
import oscP5.*;
import netP5.*;

NetAddress myRemoteLocation;

void setup() {
 size(400,400);
 frameRate(25);
 myRemoteLocation = new NetAddress("127.0.0.1",5500);
}

void draw() {
 background(0);  
}

// sending messages when key pressed
void keyPressed() {
 OscMessage myMessage;
 switch(key) {
   case('1'):
   myMessage = new OscMessage("/X");
   // create an OSC message with address pattern /Y
   for(int i=0;i<400;i++) {
     // add an int to the osc message
     myMessage.add(int(random(255)));
   }
   // we can just flush the message here.
   // OscP5.flush is a static function and we dont need to declare
   // an instance of oscP5.
   OscP5.flush(myMessage, myRemoteLocation);
   break;
   case('2'):
   // create an OSC message with address pattern /Y
   myMessage = new OscMessage("/Y");
   for(int i=0;i<400;i++) {
     // add an int to the osc message
     myMessage.add(int(random(255)));
   }
   // we can just flush the message here.
   // OscP5.flush is a static function and we dont need to declare
   // an instance of oscP5.
   OscP5.flush(myMessage, myRemoteLocation);
   break;
 }
}
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #12 - Nov 28th, 2009, 12:03am
 
Thanks a lot for this clear example.  Smiley

I can't make use of keyPressed() and case() because the experiment i'm trying to do requires both data to be sent continuously, at the same time or alternatively, to draw a shape.

for instance, if i create a circle in the sender sketch, i need to see the very same one in the receiver.

i'm not really sure if it does make sense.
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #13 - Dec 1st, 2009, 4:31am
 
Sojamo, i still haven't found a way to do it  Sad

Can you help me ?
Re: oscP5: ArrayIndexOutOfBoundsException
Reply #14 - Dec 1st, 2009, 9:27pm
 
hi jaylfk,
in this case both of your sketches should be identical except the sending and listening ports must be reversed for each sketch. in the example below each sketch stores the incoming coordinates in 2 float arrays which are then used in draw() to draw the circle coordinates received from the other sketch. your sketch and oscP5 are running their own thread, therefore the update of data might not happen concurrently which might results in flickering. at this point oscP5 only supports a data push model (incoming data from the network is pushed straight into your sketch no matter what your sketch is currently doing, this could even happen in the middle of the sketch drawing into the display window) but that makes me realize pulling data from oscP5 would be a valuable addition. but for now i hope the example below points you in the right direction.
Quote:
// 2009-12-01 http://bit.ly/6Fo2RC
// oscP5 example, sending and receiving float arrays.
// ! make sure you reverse the listening port and receiver port
// when using with a second sketch!

import oscP5.*;
import netP5.*;


OscP5 oscP5;
NetAddress myRemoteLocation;

float drawX, drawY;
OscMessage myMessageX, myMessageY;

float[] incomingX, incomingY;
int pointCount;

int updateCnt;
void setup() {
  size(400,400);
  frameRate(25);
  OscProperties props = new OscProperties();
  // increase the default datagram size used by oscP5
  // because we are receiving a lot of values at a time.
  props.setDatagramSize(4096); 
  // set the listening port for oscP5
  props.setListeningPort(5500);
  // initialize oscP5
  oscP5 = new OscP5(this,props);

  oscP5.plug(this, "positionX","/X");
  oscP5.plug(this, "positionY","/Y");
  myRemoteLocation = new NetAddress("127.0.0.1",5501);

  pointCount = 360;
  incomingX = new float[pointCount];
  incomingY = new float[pointCount];
}

void draw() {
  background(0);
  if(mousePressed) {
    myMessageX = new OscMessage("/X");
    myMessageY = new OscMessage("/Y");
    for (int i=0; i<pointCount; i++){
      drawX = sin(radians(i))*200+(width/2);
      drawY = cos(radians(i))*200+(height/2);
      fill(random(10,255),random(10,255),random(10,255));
      ellipse(drawX,drawY,4,4);
      myMessageX.add(drawX);
      myMessageY.add(drawY);
    }
    oscP5.send(myMessageX, myRemoteLocation);
    oscP5.send(myMessageY, myRemoteLocation);
  }
  // use a counter variable to turn on/off the drawing of received data
  // otherwise, if data is received at an unfavorable point in time,
  // the drawing of incoming data might result in flickering.
  // whenever data has been received the counter variable is set
  // to 0 and will draw the circles as long as the counter variable
  // does not grow bigger than its threshold.
  if(updateCnt++<2) {
    for(int i=0;i<pointCount;i++) {
      fill(random(10,255),random(10,255),random(10,255));
      ellipse(incomingX[i],incomingY[i],4,4);
    }
  }

}

void positionX(float[] theValues) {
  incomingX = theValues;
  updateCnt = 0;
}

void positionY(float[] theValues) {
  incomingY = theValues;
  updateCnt = 0;
}


Pages: 1 2