Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move SettingsDialog and ErrorDialog in jme3-awt-dialogs module #1748

Closed
wants to merge 5 commits into from

Conversation

riccardobl
Copy link
Member

@riccardobl riccardobl commented Jan 17, 2022

This PR removes SettingsDialog and ErrorDialog from the internal code, since they do not work properly in some platforms when AWT is initialized in the same thread of GLFW. ErrorDialog also causes issues with mouse release on fullscreen apps in linux.

SettingsDialog is turned into a standalone class for developers that still wish to use it, by doing so we make it easier to replace with something else, eg. a configurator that takes settings from an external launcher with commandline arguments or environment variables

AppSettings settings=new AppSettings(true);
if(SettingsDialog.showDialog(settings)){
  app.setSettings(settings);
  app.start();
}

ErrorDialog is replaced by an error message handler that can be configured by the developer to show/log/send the error message in the most appropriate way.

Eg. reimplementing the ErrorDialog to reproduce the current behavior will look like this:

JmeSystem.setErrorMessageHandler((message)->{
   ErrorDialog.showDialog(message);
});

By default on desktop ErrorDialog is not used and the error is only printed to System.err.
On android the behavior remains the same since the current error reporting is reimplemented using a default error message handler.

@riccardobl riccardobl force-pushed the macNatives branch 4 times, most recently from 1ca275b to 92291b6 Compare January 17, 2022 10:09
@stephengold stephengold added this to the Future Release milestone Jan 18, 2022
@riccardobl
Copy link
Member Author

If there is no objection i think this can be merged

@stephengold
Copy link
Member

I'd like more time to study this please.

@stephengold
Copy link
Member

This would be much easier to review if it were split into 3 PRs: one for the native libraries, one for the settings dialog, and one for the error dialog. Would you mind splitting it up please?

@stephengold
Copy link
Member

Also, the dialog changes have major impact so I think they should be discussed at the Hub/Forum before this is integrated.

@riccardobl
Copy link
Member Author

riccardobl commented Jan 18, 2022

I'll remove the native patch from this PRs and commit it directly, since it is a trivial change of the build script.
Error and Settings dialogs are part of the same problem and prevent the engine from working in MacOS and they are already split in different commits.

I don't see this as a major change, since the same functionality is provided with SettingsDialog.showDialog(settings) and ErrorDialog.showDialog(message), but i'll open a thread

@riccardobl riccardobl changed the title Add Apple M1 natives. Remove SettingsDialog and ErrorDialog Remove SettingsDialog and ErrorDialog Jan 18, 2022
@stephengold
Copy link
Member

stephengold commented Jan 18, 2022

I notice that the "Show Setting" checkbox in the test chooser no longer works. Please fix that.

I'll remove the native patch from this PRs and commit it directly, since it is a trivial change of the build script.

Thanks.

Error and Settings dialogs are part of the same problem and prevent the engine from working in MacOS and they are already split in different commits.

OK, I'll try viewing them that way.

I don't see this as a major change, since the same functionality is provided with SettingsDialog.showDialog(settings) and ErrorDialog.showDialog(message)

I disagree. If you won't start the discussion, then I will. But I imagine you could explain the changes better than I.

@riccardobl
Copy link
Member Author

I notice that the "Show Setting" checkbox in the test chooser no longer works. Please fix that.

Should be fixed now

I disagree. If you won't start the discussion, then I will. But I imagine you could explain the changes better than I.

I opened a thread here

@stephengold
Copy link
Member

Should be fixed now

Tested and confirmed.

I opened a thread here

Looks good. Thank you.

@stephengold
Copy link
Member

I got distracted today and didn't have time to study this PR in depth. Hopefully tomorrow...

@stephengold
Copy link
Member

stephengold commented Jan 19, 2022

I don't understand why the SKIP_SETTINGS variables were removed from TestIssue1120 and TestGImpactShape. How do those changes relate to this PR?

@riccardobl
Copy link
Member Author

Isn't SKIP SETTING used to skip the setting dialog there?

@stephengold
Copy link
Member

Isn't SKIP SETTING used to skip the setting dialog there?

Yes. And?

@riccardobl
Copy link
Member Author

If the settings dialog is removed it cannot unskip it

@stephengold
Copy link
Member

Okay, the removals make sense then.

I'm trying to run apps in jme3-examples on Linux (this branch of JME) and every test so far has failed. Here's a typical crash log:

> Task :jme3-examples:run
Jan 19, 2022 9:31:30 PM com.jme3.system.JmeDesktopSystem initialize
INFO: Running on jMonkeyEngine 3.1.0-SNAPSHOT
 * Branch: macNatives
 * Git Hash: f6d099e
 * Build Date: 2022-01-19
Jan 19, 2022 9:31:30 PM com.jme3.app.LegacyApplication handleError
SEVERE: Failed to create display
java.lang.RuntimeException: Unable to find fullscreen display mode matching settings
	at com.jme3.system.lwjgl.LwjglDisplay.createContext(LwjglDisplay.java:80)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:120)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:221)
	at java.lang.Thread.run(Thread.java:748)

[JME ERROR] Failed to create display
RuntimeException: Unable to find fullscreen display mode matching settings
Jan 19, 2022 9:31:30 PM com.jme3.app.LegacyApplication handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,6,main]
java.lang.IllegalMonitorStateException
	at java.lang.Object.notifyAll(Native Method)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:135)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:221)
	at java.lang.Thread.run(Thread.java:748)

[JME ERROR] Uncaught exception thrown in Thread[jME3 Main,6,main]
IllegalMonitorStateException

Exception: java.lang.NullPointerException thrown from the UncaughtExceptionHandler in thread "jME3 Main"

@Ali-RS
Copy link
Member

Ali-RS commented Jan 20, 2022

Running on jMonkeyEngine 3.1.0-SNAPSHOT

Why 3.1?

@stephengold
Copy link
Member

Why 3.1?

I noticed that, too. I suppose that might be because Riccardo's fork lacks any recent build tags:

sgold:~/Git/riccardo/jmonkeyengine$ git tag
3.1-github-tag-test
3.1-snapshot-test
3.1-snapshot-test-2
3.1-snapshot-test-3
3.1-snapshot-test-4
test123
test124
v3.1-alpha1
v3.1.0-alpha2
v3.1.0-alpha3
v3.1.0-alpha4
sgold:~/Git/riccardo/jmonkeyengine$

The branch of "macNatives" from "master" took place less than a week ago.

@riccardobl
Copy link
Member Author

Somehow it seems the window is launcher fullscreen

@stephengold
Copy link
Member

I'm interested in writing a new version of Settings Dialog that doesn't use AWT/Swing.

@riccardobl: Instead of removing/disabling the dialogs, would you consider revising this PR so it's not a breaking change?
In other words, add the hooks to replace Settings Dialog and Error Dialog with alternatives, but keep the current dialogs as the defaults on all platforms.

@riccardobl
Copy link
Member Author

riccardobl commented Mar 25, 2022

I am planning to move the dialogs on a jme3-awt-dialogs module that can be replaced with a different module for different platforms or left out for no dialogs. Would that work?

@stephengold
Copy link
Member

I think it would.

@riccardobl riccardobl changed the title Remove SettingsDialog and ErrorDialog Move SettingsDialog and ErrorDialog in jme3-awt-dialogs module Apr 3, 2022
@riccardobl
Copy link
Member Author

riccardobl commented Apr 3, 2022

Done.
I've moved the awt dialogs into the optional jme3-awt-dialogs module and added a "settings handler" in JmeSystemDelegate to handle the initial configurations.

Both error and settings handlers will search by default the classcom.jme3.system.JmeDialogsFactoryImpl that implements JmeDialogsFactory. If found they will call JmeDialogsFactoryImpl.showErrorDialog() and JmeDialogsFactoryImpl.showSettingsDialog(), if not found the settings handler will do nothing and the error handler will print the error message to System.err.

I've implemented the JmeDialogsFactoryImpl in jme3-awt-dialogs to keep the current behavior when the new module jme3-awt-dialogs is included as dependency.
To implement new dialogs the process is to create a new module (eg. jme3-fx-dialogs) and the class com/jme3/system/JmeDialogsFactoryImpl that implements JmeDialogsFactory inside the module.

To reduce the complexity and to have the entire logic selfcontained into the default handlers and the module i made so that a new instance of JmeDialogsFactoryImpl is created everytime a dialog is shown, it shouldn't be a problem, but if proven otherwise i will figure out a different approach.

@riccardobl
Copy link
Member Author

I'm interested in writing a new version of Settings Dialog that doesn't use AWT/Swing.

@stephengold let me know if this meets the requirements for the new dialogs

@stephengold
Copy link
Member

I'll study it. Thanks!

@stephengold
Copy link
Member

I've begun studying this PR. So many levels of indirection!

I understand correctly, I can create a new library with its own version of com.jme3.system.JmeDialogsFactoryImpl, and applications including that library will automatically use it to generate settings dialogs and error dialogs as needed. That seems sufficient for what I'm interested in doing.

By the way, something I noticed: SimpleApplication.start() is still invoking the deprecated showSettingsDialog() method in JmeSystem. I guess it ought to directly invoke handleSettings() instead?

@riccardobl
Copy link
Member Author

I understand correctly, I can create a new library with its own version of com.jme3.system.JmeDialogsFactoryImpl, and applications including that library will automatically use it to generate settings dialogs and error dialogs as needed. That seems sufficient for what I'm interested in doing.

Yes, that's correct.

By the way, something I noticed: SimpleApplication.start() is still invoking the deprecated showSettingsDialog() method in JmeSystem. I guess it ought to directly invoke handleSettings() instead?

Yes handleSettings is the new method.

If you are happy with this, i will fix the conflicts and remove the deprecated calls so that it can be merged.

@stephengold
Copy link
Member

In my opinion, this PR isn't ready to be merged yet. At the very least, it needs javadoc and reformatting.

@riccardobl
Copy link
Member Author

Added the missing documentation.
Should i refactor this to use a system similar to what @Ali-RS described in this thread https://hub.jmonkeyengine.org/t/buffer-allocator-implementation-set-by-lwjglcontext-gets-ignored-sometimes/45594/9?u=riccardoblb ?
I.e. using config files

@Ali-RS
Copy link
Member

Ali-RS commented May 24, 2022

I.e. using config files

IMHO, the current implementation is fine, I believe no need to use a config file in this case.

@stephengold
Copy link
Member

I'd like to integrate this PR. However I can't figure out how to do so using the mechanisms built into GitHub. My plan is to integrate the diffs into a new branch in the main repo, but I'm open to other suggestions on how to proceed.

@MeFisto94
Copy link
Member

The alternative would be to locally rebase the macNatives branch onto master and then force-push (or merge master into that branch and regularly push).
Do not copy over the files, though, as that conflicts may be meaningful.

@pspeed42
Copy link
Contributor

pspeed42 commented Dec 7, 2022

Force pushing messes up anyone who has the repository checked out. Better to do things a different way.

@MeFisto94
Copy link
Member

anyone who has this feature branch checked out (that is actually even on the fork repo).
Could also rebase and push onto this repo, however.

@stephengold
Copy link
Member

The alternative would be to locally rebase the macNatives branch onto master

I tried that and ran into difficulties that I didn't know how to handle.

Please @MeFisto94, if you know how to do this right, please do so!

@MeFisto94
Copy link
Member

Done in https://github.com/jMonkeyEngine/jmonkeyengine/tree/pr/1748
Sadly I can only change this PR's target branch not the source branch.

@stephengold
Copy link
Member

Very neat. I'll open a new PR for the changes.

@stephengold
Copy link
Member

Done! Integrated into "master" branch at 9e54d44
Thanks to @MeFisto94

@stephengold stephengold closed this Dec 8, 2022
@stephengold stephengold removed this from the Future Release milestone Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants