TimedEvents library problem

Hi everyone,

Excuse my poor english.
I´m having problems with TimedEvents library. I can not get it to draw anything. Even examples doesn´t work. Nothing inside void onTimerEvent() draw anything.

import org.multiply.processing.TimedEventGenerator;

TimedEventGenerator ellipseTimedEventGenerator;

void setup() {
  size(400, 400);
  background(255);
  ellipseTimedEventGenerator = new TimedEventGenerator(this);
  ellipseTimedEventGenerator.setIntervalMs(1500);
}

void draw() {
  fill(20);
  ellipse(100, 100, 30, 30);
  //      ellipse(random(width), random(height), random(100), random(100));
}
void onTimerEvent() {
  println("now", millis());
  fill(20);
  ellipse(random(width), random(height), random(100), random(100));
}

1 Like

Place this statement at the beginning of onTimerEvent() callback:
println(Thread.currentThread());

If it doesn’t log something like: Thread[Animation Thread,5,main].
It means another Thread is executing that callback and we can’t “draw” anything there!

As a workaround, you can have some global boolean variable and set it true inside onTimerEvent().

Inside draw(), keep checking that flag variable each iteration, so it knows when it has to “draw” what it was previously inside onTimerEvent().

Of course after that, you’re gonna need to revert it back to false.

Take a look at the sketch link below for a similar example on how to do it:

2 Likes

Yes! I did it just like that, but I thought I had done something wrong with TimedEvents library because it’s one of the official libraries and not even the examples work. The answer is “Thread[pool-1-thread-1,5,main]”.

Thanks! As always “un capo” or “un genio”: