HI - I have been experiencing random an intermittent lock ups of my application. I am using G4P 4.1.5 on processing 3.3.7 so all upto date.
I have worked out that my problem is caused by using multiple windows with a slider control that updates a text area/label displayed on another window.
Does anyone know if there is a better way to achieve this or is this simply a not possible with processing?
The following code demonstrates the problem – it uses a knob control to update a GTextArea object.
When the slider and text area are instantiated on different windows (as in the demo code) the problem happens randomly before lockup, from almost immediately to up to a few minutes.
When the slider and text area are on the same window the problem does not occur.
import g4p_controls.*;
GWindow window_setup;
GKnob setup_knob;
GTextArea text;
GLabel label;
boolean cntdwn=false;
void setup() {
size(250, 200, JAVA2D);
//window setup
window_setup = GWindow.getWindow(this, "settings", 70, 160, 250, 200, JAVA2D);
window_setup.addDrawHandler(this, "window_setup_draw");
//GTextArea / GLabel- cause java.util.ConcurrentModificationException
// or java.lang.NullPointerException amongst others?
// when accessed from separate window
text = new GTextArea(this, 20, 20, 192, 45, G4P.SCROLLBARS_NONE);
//text = new GTextArea(window_setup, 20, 20, 192, 45, G4P.SCROLLBARS_NONE);
label = new GLabel(this, 25, 80, 192, 45);
//setup knob
setup_knob = new GKnob(window_setup, 20, 80, 209, 203, 0.8);
//setup_knob = new GKnob(this, 20, 80, 209, 203, 0.8);
setup_knob.setTurnRange(180, 0);
setup_knob.setTurnMode(GKnob.CTRL_HORIZONTAL);
setup_knob.setSensitivity(1);
setup_knob.setShowArcOnly(true);
setup_knob.setOverArcOnly(true);
setup_knob.setIncludeOverBezel(false);
setup_knob.setShowTrack(true);
setup_knob.setLimits(90.0, 0.0, 180.0);
setup_knob.setShowTicks(true);
setup_knob.setOpaque(false);
setup_knob.addEventHandler(this, "setup_knob_turn1");
}
void move_knob() {
if(setup_knob.getValueF()>=180)
cntdwn=true;
else if(setup_knob.getValueF()<=0)
cntdwn=false;
if(cntdwn)
setup_knob.setValue(setup_knob.getValueF()-1);
else
setup_knob.setValue(setup_knob.getValueF()+1);
}
void draw() {
background(230);
move_knob();
}
synchronized public void window_setup_draw(PApplet appc, GWinData data) { //_CODE_:window_setup:219612:
appc.background(230);
}
//pass in a millis() duration value
//returns a string with hh:mm:ss.milli format
String getElapsedTime(long duration) {
long millis=(duration%1000);
long secs=(duration/1000)%60;
long mins=(duration/(1000*60))%60;
long hours=(duration/(1000*60*60))%24;
//formating / padding with zeros
String[] time=new String[4];
time[0] = (hours<10) ? "0"+hours : ""+hours;
time[1] = (mins<10) ? "0"+mins : ""+mins;
time[2] = (secs<10) ? "0"+secs : ""+secs;
time[3] = (millis<10) ? "00"+millis : (millis<99) ? "0"+millis : ""+millis;
return time[0] + ":" + time[1] + ":" + time[2] + "."+time[3];
}
public void setup_knob_turn1(GKnob source, GEvent event) {
println("setup_knob - GKnob >> GEvent." + event + " @ " + millis()+" "+ getElapsedTime(millis()));
text.setText(setup_knob.getValueF()+"\nTest @ "+millis()+" "+ getElapsedTime(millis()));
//label.setText(setup_knob.getValueF()+"\nTest @ "+millis() +" "+ getElapsedTime(millis()));
}
On crash I get exceptions of one of either “java.lang.NullPointerException, java.util.ConcurrentModificationException, or java.lang.IllegalArgumentException: Invalid substring range”
e.g.
java.lang.NullPointerException
at java.util.LinkedList$ListItr.next(LinkedList.java:893)
at g4p_controls.GTextArea.updateBuffer(Unknown Source)
at g4p_controls.GTextArea.draw(Unknown Source)
at g4p_controls.GWindowImpl.draw(Unknown Source)
at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1408)
at processing.core.PApplet$RegisteredMethods.handle(PApplet.java:1401)
at processing.core.PApplet.handleMethods(PApplet.java:1600)
at processing.core.PApplet.handleDraw(PApplet.java:2439)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1557)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:316)
Thanks any thoughts or help appreciated!
And you can’t even do that reliably in one VM using OpenGL without crashing. This could all easily be fixed, but despite Processing shipping with a multiple windows example, it’s considered unsupported. And none of those Processing threads are the OS event thread!