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

After starting the new window has dimensions 0x0 #764

Closed
vyalyh-oleg opened this issue Mar 3, 2020 · 13 comments
Closed

After starting the new window has dimensions 0x0 #764

vyalyh-oleg opened this issue Mar 3, 2020 · 13 comments

Comments

@vyalyh-oleg
Copy link

vyalyh-oleg commented Mar 3, 2020

screenshot

On the screenshot you see the code and the result.
The window doesn't take into account the values were put to the settings. So it has as small size as the OS can let.

But i found the root of the problem (as i think). If to debug the code you may notice the minHeight and minWidth of the stage are 0-s.
Look at this code snippet from the FXGL library

public static final class FXGLApplication extends Application
{
	public static GameApplication app;
	private static ReadOnlyGameSettings settings;
	
	/**
	 * This is the main entry point as run by the JavaFX platform.
	 */
	@Override
	public void start(Stage stage)
	{
		var engine = new Engine(app, settings, stage);
		
		settings.getEngineServices().forEach(serviceClass ->
			engine.addService(ReflectionUtils.newInstance(serviceClass))
		);
		
		if (settings.getApplicationMode() != ApplicationMode.RELEASE && settings.isDeveloperMenuEnabled())
		{
			engine.addService(new DevService());
		}
		
		FXGL.inject$fxgl(engine);
		
		engine.startLoop();
	}
}

If to add such, lines everything works fine.

		stage.setMinHeight(settings.getHeight());
		stage.setMinWidth(settings.getWidth());

Environment:

OS: Linux Mint 19.3 (Cinnamon DE, GTK3)

$ java --version
openjdk 11.0.6 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)

JavaFX version: 11.0.2

FXGL version: 11.7
@AlmasB
Copy link
Owner

AlmasB commented Mar 3, 2020

Nice job figuring this out, could also be the solution to #737

I will add the proposed fix in the next commit and let you know so you can test it on your system.

@vyalyh-oleg
Copy link
Author

vyalyh-oleg commented Mar 3, 2020

Yes, i think #737 and mine are the same.

I also have a proposition:
Extend available set of GameSettings for such stage properties:

stage.setMinHeight();
stage.setMinWidth();
stage.setMaxHeight();
stage.setMaxWidth();

Because the ordinary width and height are not the maximum and minimum. They are more related to the initial size of root Scene you add to the Stage.

Or even better (i don't know how do you feel about this) -- add ability to knock to the Stage/Scene directly.

Thanks!

@AlmasB
Copy link
Owner

AlmasB commented Mar 3, 2020

Some food for thought... I'll give it a go some time tomorrow and see what works best.

@AlmasB
Copy link
Owner

AlmasB commented Mar 4, 2020

Before moving this further, please can you check if using dev-SNAPSHOT fixes the issue.
To get the latest build, you can use this:

<dependencies>
    <dependency>
        <groupId>com.github.almasb</groupId>
        <artifactId>fxgl</artifactId>
        <version>dev-SNAPSHOT</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>oss.sonatype.org-snapshot</id>
        <url>http://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>

The next version (dev snapshot) uses JavaFX 13, which according to this thread fixes the window size issues.

@vyalyh-oleg
Copy link
Author

vyalyh-oleg commented Mar 4, 2020

The dev-SNAPSHOT doesn't work too.

When i put break point at the very end the start method and check the stage dimensions (min Height and Width) they are still zeros.

If i add two lines of code like below -- it works:

        public void start(Stage stage) {

            stage.setMinHeight(768);
            stage.setMinWidth(1024);

            Thread.setDefaultUncaughtExceptionHandler((thread, e) -> {
                this.handleFatalError(e);
            });
            GameApplication.log.debug("Initializing FXGL");
            this.engine = new Engine(settings);
            FXGL.inject$fxgl(this.engine, app, this);
            StartupScene startupScene = settings.getSceneFactory().newStartup();
            MainWindow mainWindow = new MainWindow(stage, startupScene, settings);
            mainWindow.show();
            this.engine.getEnvironmentVars$fxgl().put("settings", settings);
            this.engine.getEnvironmentVars$fxgl().put("mainWindow", mainWindow);
            this.engine.initServicesAndStartLoop();
        }

p.s. Yes i've read about jfx-13 version, but i thought the fix will be available for 11 version too.
As an experiment, could you make such a simple build where the stage min Height and Width are set at the beginning of the method (or add the ability to get stage object directly). I'll check it.

I faced with similar problems on my other pet-projects and such solution help me.

@vyalyh-oleg
Copy link
Author

I'll try with jfx-13 tomorrow.

@AlmasB
Copy link
Owner

AlmasB commented Mar 5, 2020

Interestingly I could not reproduce the issue using, though I am running this on a virtual box.

Linux Mint 19.3
openjdk 11.0.4
javafx runtime: 10.0.2-internal (not sure how this was picked up since the dependency is on 13 ...) and 12.0.1
gtk: 2 and 3
FXGL version: 11.7

I will try a different OS mentioned in the other issue. If I can't reproduce, I will probably try something like this in MainWindow.kt:

stage set min width height to initial
show
stage set min width height to 0 
(I think we need to do the above to keep the window resize behavior consistent with current version)

@AlmasB
Copy link
Owner

AlmasB commented Mar 5, 2020

Right, I've reproduced the issue with manjaro kde linux, with javafx 12.0.1. After switching to dev-SNAPSHOT, which uses javafx 13.0.2, everything is fine. Please can you try to enable jfx-13 somehow (I don't know why the same fxgl build gets linked to different jfx runtimes).

The log should say: FX:13.0.2, which is the jfx runtime version.

@vyalyh-oleg
Copy link
Author

vyalyh-oleg commented Mar 5, 2020

I've changed the version of javafx.

INFO  Engine - FXGL-11.7 (05.01.2020 09.37) on LINUX (J:11.0.5 FX:13.0.2)

Now it works ! Even with the FXGL-11.7.
But the window is not re-sizable.

@AlmasB
Copy link
Owner

AlmasB commented Mar 5, 2020

The window by default is not resizable, you need to enable it via settings.setManualResizeEnabled(true);

@vyalyh-oleg
Copy link
Author

Thanks! I think the problem is settled.

@AlmasB
Copy link
Owner

AlmasB commented Mar 6, 2020

Great! I'll keep the issue open until 11.8 is released.

@AlmasB
Copy link
Owner

AlmasB commented Mar 8, 2020

Fixed in 11.8 by upgrading the jfx dep to 13.0.2

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

No branches or pull requests

2 participants