PWindow win;
public void settings() {
size(320, 240);
}
void setup() {
surface.setLocation(20,20);
//win = new PWindow();
}
void draw() {
background(255, 0, 0);
fill(255);
rect(10, 10, frameCount, 10);
}
void mousePressed() {
println("mousePressed in primary window");
if(win == null) win = new PWindow();
}
class PWindow extends PApplet {
PWindow() {
super();
PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
}
void settings() {
fullScreen();
}
void setup() {
background(150);
}
void draw() {
ellipse(random(width), random(height), random(50), random(50));
println("mousePressed in secondary window");
}
void keyPressed() {
//if it is esc key then close the window
}
void exit()
{
dispose();
win = null;
}
}
And afte rthe second fullscreen sketch closes, the parent sketch still runs.
It would be great if you can spare some time and give me some suggestions. Or code hahahah
(1) In your code when the fullscreen window is is created it hides all other windows and becomes the active window which means ALL key and mouse events are sent to it. The original sketch window is effectively deaf and dumb and will not respond to key and mouse events these events can’t be used to close the secondary window. It is worse than that because it is not easy to make the sketch window the active one.
(2) You can force the sketch window to remain on top by adding the line surface.setAlwaysOnTop(true); to the setup method. You can see it in the code below. Simply clicking on the sketch window will then make it active.
(3) The method used to close the window depends on whether it uses the JAVA2D renderer (Java AWT, default) or P2D / P3D renderer (OpenGL)
I have modified your code and added some new methods to the PWindow class. If you run the sketch and click on the window your fullscreen window opens. Type the key ‘x’ and the secondary window closes leaving the sketch window open. If the secondary window uses P2D/P3D then a secondary NPE exception is generated but it doesn’t seem to cause any problems.
I have tried your example and it works great with the processing renderer.
Unfortunately as you said there is an exception when using the P2D/P3D renderer.
In my case this is thrown:
Sometimes the OpenGL error 1282 is there and sometimes not.
The second window gets inactive but does not close or dispose.
Is my assumption right that a thread is still running which tries to draw in the window? noLoop() in the second window before closing didnt do the trick.
I try to close the window and restart it in fullscreen or “normal” (changing by F11). The restart works which means i get a lot of windows when the old one is not closed.
EDIT: After playing around a bit and testing i discovered this:
Caught subsequent NullPointerException: null on thread Animation Thread-FPSAWTAnimator#00-Timer0
For each window i try to close there is added a timer:
Caught subsequent NullPointerException: null on thread Animation Thread-FPSAWTAnimator#00-Timer0-FPSAWTAnimator#01-Timer1-FPSAWTAnimator#02-Timer2-FPSAWTAnimator#03-Timer3
I think that my assumption of threads still running is right. But i also know that i dont have a clue on what to do now.
The problem seemed to have solved itself.
I have tested the Processing 4.0 beta 1 app. Somehow some of my periphery for my middle mouse button from my sketch didnt work in here so i switched back to 3.5.4. (Both apps are installed at the same time)
Now it works and i have no clue why. Maybe 3.5.4 is now using updated libraries but i cant tell anything else than: it works.
Also without any errors.
I thought that maybe is interesting or helpful for someone.