Hi Philip, Thank you a lot for these helpful clarifications.
You are right, I definitely need to jump on a dedicated OS thread. It is a pity the -XstartOnFirstThread does not do it. We may probably use JOGL's OSXUtil class that does a good job at handling this already. The only limitation is that getting OSXUtil requires depending on all JOGL which additionally requires tweaks to avoid hangs and the like. Regards, Martin ------- Original Message ------- Le mardi 18 avril 2023 à 19:52, Philip Race <[email protected]> a écrit : > 1) -XstartOnFirstThread should be thought of more as -XdontStartAnEventLoop > And with no event loop running, yes, UI apps hang. > To understand why the option is named as it is, you need to know that on most > platforms > and situations the application's "main" method will run on the first thread > that is started > But on macOS in order to allow the event loop to run on that thread, it hops > over to another > thread that is created. But with this special option, that doesn't happen, so > some other code > has a chance to use it for that. > The reason for it is that a toolkit like SWT may come along later and start a > loop. > It is possible to check there's already a loop (AWT + JavaFX both do) but > perhaps SWT doesn't ? > In summary this option is not (SFAICS) for your use case and that bug is "not > a bug" and I've closed it. > > 2) The class referenced by Sergey > > https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/java2d/opengl/OGLUtilities.java > > isn't one I know anything about. I can see it pre-dates us even having a > macOS port, and its completely > unsupported, probably unsupportable, no idea if it actually works, especially > on macOS. > Not sure if its even a direction you should head down. Caveat emptor. Big > time. > > 3) JAWT is a JDK native API that lets you use native code to draw into a > Java-owned window. > https://docs.oracle.com/en/java/javase/17/docs/specs/AWT_Native_Interface.html > It doesn't provide much more than that. Any rendering that needs to happen on > a particular thread > etc is out of scope of what it provides. > > 4) Your error isn't obviously directly opengl related even though it mentions > "GLUT". Its more about the toolkit. > > java[92246:2751169] GLUT Fatal Error: internal error: > NSInternalInconsistencyException, reason: NSWindow drag regions should only > be invalidated on the Main Thread! > > I would have thought that the advice which I think you need (in this somewhat > confusing thread) people > have already offered and this is to jump onto the main thread when needed. > You can look at the code in the JDK's libosxapp/ThreadUtilities.m as a sample > to see how you'd do this. > Do not rely on JDK internals. Ultimately you will need to end up using this > Apple macOS API - > https://developer.apple.com/documentation/objectivec/nsobject/1414900-performselectoronmainthread > - if you aren't already on the main thread that is. > If there's some complication with that which I'm not understanding, I don't > know what you'd do instead. > > I don't have time to look into this any more deeply so this reply must be > taken as not fully researched, > but it is the best I can offer you. > > -Phil > > On 3/23/23 4:00 AM, Martin Pernollet wrote: > >>> Start another java process -XstartOnMainThread that does the OpenGL part >>> from a Swing application? >> >> Sorry I do not understand your question. If you speak about triggering two >> process with -XstartOnFirstThread, I think they might both freeze. Or worse, >> one freeze and the other one get kick/stopped by the former. >> >> I can try this next week because I do not have a macOS with me up to next >> thursday. >> >>> One hang up there though might be that I don’t think java applications that >>> include the java native commands are allowed in the Mac App Store. Another >>> bug due to each command has it’s own unique CFBundleIdentifier but that >>> identifier is always the same and Apple doesn’t allow duplicates in the App >>> Store. >> >> Being able to deploy on App Store is not an immediate need for me but this >> is a very interesting point to consider. I'll try to understand how >> CFBundleIdentifier relates to -XstartOnFIrstThread. >> >> Regards, >> >> Martin
