Can't draw on main window, calling methods from a secondary window (PApplet, image())

Hello !

From the main processing sketch file, I am instantiating objectA that defines methodA, which draws stuff on a PImage, that it then draws on the main window, using the image() function. This works as expected, whenever the method is called from another basic object (an object of a class that is not extending PApplet). I am also instantiating objectB, whose class extends PApplet, to control a secondary window. In objectB, I have a knob that I want to use to control the background color of the main window: whenever the user interacts with this knob, methodA in objectA is triggered by objectB (of course, objectB is holding a valid** reference to objectA, set from the main sketch file). When methodA is called from inside objectB, nothing is displayed on the main window by the image() function (which is called inside methodA), even if I have instantiated objectA from the main sketch file. Why is that ? I would expect image() to be dependent on the object it is called from (i.e. objectA, and not objectB). Should I find a reference to the main window, instead, right from inside objectB or objectA and then do something like:

mainWindow.image(im, 0, 0);

instead of

image(im, 0, 0);


I hope this is somehow understandable. Thank you for stopping by, have a good day, folks :palm_tree::wink:

**it can print correctly to the console

The short answer is that it is not allowed by Java.

Each window has its own main event handling thread and any drawing to this window must be done inside its own thread,