/**
* Threaded color() Access Test (v1.0)
* GoToLoop (2018/Dec/13)
* https://Discourse.Processing.org/t/processing-bug/6561/10
*/
// Blinks magenta from time to time:
static final String THREADED_METHOD = "colorThreadBug";
// Always blue background():
//static final String THREADED_METHOD = "colorThreadWorkaround";
void setup() {
size(300, 200);
thread(THREADED_METHOD);
}
void draw() {
background(#0000FF);
getSurface().setTitle("Frames: " + frameCount);
}
void colorThreadBug() {
for (;; delay(1)) color(#FF0000);
}
void colorThreadWorkaround() {
final PGraphics offscreenColor = createGraphics(0, 0);
final java.lang.reflect.Method colour;
try {
colour = PGraphics.class.getMethod("color", int.class);
}
catch (final NoSuchMethodException e) {
throw new RuntimeException(e);
}
try {
for (;; delay(1)) colour.invoke(offscreenColor, #FF0000);
}
catch (final ReflectiveOperationException e) {
throw new RuntimeException(e);
}
}