2 PApplets synchronization

In my Java programme (running on Win10) I have several PApplets created with runSketch(). Sometimes an error occurs (see below). I suspect it is caused by one thread being called before some precomputations in another thread have finished. How can I make one PApplet wait for another to finish precomputations? Is it possible with wait() notifyAll().

java.lang.NullPointerException
at processing.opengl.PShapeOpenGL.updatePolyIndexCache(PShapeOpenGL.java:3638)
at processing.opengl.PShapeOpenGL.aggregateImpl(PShapeOpenGL.java:3608)
at processing.opengl.PShapeOpenGL.aggregateImpl(PShapeOpenGL.java:3596)
at processing.opengl.PShapeOpenGL.aggregate(PShapeOpenGL.java:3556)
at processing.opengl.PShapeOpenGL.updateTessellation(PShapeOpenGL.java:2766)
at processing.opengl.PShapeOpenGL.draw(PShapeOpenGL.java:4678)
at processing.core.PGraphics.shape(PGraphics.java:3996)
at processing.core.PApplet.shape(PApplet.java:12873)
at StrFrame.display(StrFrame.java:148)
at SecondApplet.displayStrFrames(SecondApplet.java:822)
at SecondApplet.draw(SecondApplet.java:580)
at processing.core.PApplet.handleDraw(PApplet.java:2482)
at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:866)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

Hi @gerome,

Without any code / reproducible example, we can’t help you further! Can you try to post it? :wink:

Hi josephh, thanks for your reply. I solved my problem meanwhile using noLoop() / loop() to avoid running the second PApplet´s draw() loop until heavy precomputations are done. I called these methods from the first Applet´s setup(). Posting code is diffcult b/c the java project contains several 10K lines of code.

3 Likes