When you use the mouse then you are generating events which are trapped by Processing and we can add our code in methods such as mousePressed() and mouseReleased() etc to perform some task.
Even if we don't include a particular method e.g. mouseReleased() the event is still being produced but it is handled by Processing.
When you press the mouse button and release it without moving the mouse position it generates 3 events
mousePressed
mouseReleased
mouseClicked
in that order (try the code below). Note if the mouse has moved then you only get the first 2 events.
The important thing to note is that events are queued and processed one at a time, the code for each event being executed in full before the next event is taken off the queue and processed. So the mouseReleased code cannot be executed until the mousePressed code finishs. Which makes your problem interesting and I suspect the problem is caused by something else.
If you try the following code you will see what I mean
Code:
int arraylength = 5000000;
float[] foo = new float[arraylength];
void setup(){
size(300,300);
}
void draw(){
}
void mousePressed(){
println("mouse pressed");
for(int i=0; i<arraylength; i++) {
foo[i] = round(sin(sqrt(((i/10) * i+random(1,100)))));
}
println("mouse pressed end");
}
void mouseReleased(){
println("mouse released");
}
void mouseClicked(){
println("mouse clicked");
}
The "mouse pressed end" message always appears before the "mouse released" message.
There is an alternative way to handle mouse events in Processing and the code shows how to do it. You might try this approach and see if it fixes the problem.
Code:int counter = 0;
int arraylength = 5000000;
float[] foo = new float[arraylength];
void setup(){
size(300,300);
registerMouseEvent(this);
}
void draw(){
}
public void mouseEvent(MouseEvent event){
switch(event.getID()){
case MouseEvent.MOUSE_PRESSED:
println("mouse pressed");
for(int i=0; i<arraylength; i++) {
foo[i] = round(sin(sqrt(((i/10) * i+random(1,100)))));
}
println("mouse pressed end");
break;
case MouseEvent.MOUSE_CLICKED:
println("mouse clicked");
break;
case MouseEvent.MOUSE_RELEASED:
println("mouse released");
break;
}
}
Hope this helps.