Yes the standard behaviour is to close the window or exit single-window applications but all OSs allow the user to change how things work on their computer so a user can get confused when using someone else’s even if they have the same OS. So I don’t think it’s a big deal.
OK so lets see how Processing handles multiple windows.
The first thing to remember is that Processing was not designed to create multi-window applications so if you search the forum you will find many examples of people creating simple classes to represent a window. The problem is that by default when the secondary window closes it closes the whole application, and that is not standard OS behaviour.
G4P provides a simple way to produce fully-featured secondary windows, both AWT (JAVA2D - default mode) and OpenGL (P2D and P3D mode). In early versions of G4P, closing the secondary window closed the application i.e. Processing’s default behaviour. The current version gives the user three options
EXIT_APP
This keeps Processing’s default behaviour.
KEEP_OPEN
As the name suggests it causes the window to ignore windows close events such as clicking on the red-cross.
CLOSE_WINDOW
This will close the window (without exiting the app) and release all resources associated with the window e.g. any G4P controls on the window
There are no issues with stability regarding the first 2 options. Apart from a couple of reports from Linux users the close-window option works fine as well.
My only concern is that opening and closing a GWindow multiple times is
wasteful of CPU time
if not properly coded by the user can lead to memory leaks and null pointer exceptions
not proven to be stable on all platforms.
Having this discussion has given me an idea
Why not a fourth option - HIDE_WINDOW this would have the benefit that the user get the expected behaviour and it would not have the problems associated with CLOSE_WINDOW.
I’ll try the HIDE_WINDOW option, I didn’t realize this option existed. (What’s the difference between hiding a window and making it invisible?) Don’t bother spending time on the source code.
I wouldn’t bother then. I’m OK with the existing options. I’ll try testing it under Linux today and see what happens. When you say it’s unstable, what are the symptoms? What should I look for?
I have created a sketch that demonstrates the HIDE_WINDOW option I would appreciate it if you would download it and try it out. The sketch is completely self contained and will not affect your installation of G4P or any other sketches using G4P.
I tested it under both Windows 7 (64 bit) and Ubuntu Studio (64 bit), using both the Java AWT and OpenGL. It works fine under WIndows using either renderer, and also under Linux, except when I close the sketch while using OpenGL. Under Linux, I get different error messages when I close the sketch, depending on how I close it (by pressing ESC or clicking on the Exit icon). This may be due to not having a good OpenGL driver installed for Linux, or maybe it’s a problem in Processing itself. I’ve seen a number of posts suggested that the OpenGL renderer is deprecated, but I’m not sure why. But even under Linux using OpenGL, it seems to work fine until I close the sketch.
Attached is one of the error messages I get when closing under Linux using the OpenGL renderer.
Thanks very much for testing the sketch it was really helpful. Based on what you reported and what I found on OSX I will include it in the next release.
Glad I could help, after all the help you’ve given me. But what do you think is causing the error message in Linux? Do I need to update the driver for OpenGL? Or is it a problem in Processing?
I don’t know the cause of the error but since each window has its own main event dispatch thread there maybe a timing issue between threads when closing down. This is one reason is why I recommend not to repeatably close / recreate windows, especially OpenGL windows. Did you notice how long the 3D window took to create?
As to the OpenGL drivers it is probably worth keping them upto date for your graphics card.
By 3D, you mean the OpenGL version? It’s quite sluggish coming up for the first time, about 3 sec. Once it’s been created, though, hiding/showing the window is quite responsive. For reference, I’m running this on an HP-P6230F with an AMD Phenom II X4 810 Processor rated at 2.60 GHz and 8 GB of RAM. (I have WIndows 7 and Ubuntu Studio installed on the same computer, in a dual-boot configuration.)
I think there’s still a problem with the OpenGL renderer, even under Windows. If I repeatedly click on the Show/Hide button, it works fine. But if I hide it using the Close icon in the top right, then re-open it with the Show/Hide button, sometimes (not always), the child window is empty (just a black background). Also, if I press [ESC] when the child window has focus, both windows close. But if I press [ESC] when the main window has focus, it crashes with a “java.lang.ThreadDeath” exception. With the Java AWT renderer though, I can press [ESC] in either window and it closes properly.You might want to do some more testing before you release this.