Just Enough Items (JEI)

Just Enough Items (JEI)

464M Downloads

[Crash]: Losing and gaining focus in fullscreen mode while using a different resolution than monitor native

TellyO3 opened this issue ยท 1 comments

commented

Steps to Reproduce the Crash

  1. Load game on 1.21.1, running Windows. (I also tested 1.21.5)

  2. Go to the video settings and set the fullscreen resolution to anything under the default, and ensure that fullscreen mode is enabled.

  3. Open any recipe in your inventory.

  4. While looking at the recipe, alt-tab out of the game, and back in, the game will now exit.

Mod Pack URL (Optional)

No response

Mod Pack Version (Optional)

No response

Extra Notes (Optional)

Hey,

I've found an issue that occurs when the game is set to a different resolution than a monitor's default. In my case, my laptops screen is 2560x1600, which I scale down to 1920x1200. When using alt + tab on Windows, or similar methods of switching screens, Minecraft resizes and crashes the game.

Looking in mezz.jei.gui.recipes.RecipesGui.init we see this piece of code:

int ySize;
IClientConfig clientConfig = Internal.getJeiClientConfigs().getClientConfig();
if (clientConfig.isCenterSearchBarEnabled()) {
	ySize = this.height - 76;
} else {
    ySize = this.height - 58;
}

When Minecraft resizes the screen could temporarily report a value smaller than 76 or 58, in my case the value is 39. And as a result the PreCondition in ImmutableRect2i throws an unhandled exception that escalates and results in the crash.

For anyone suffering from this issue, I verified and tested two hacks that I am currently using to prevent my game from crashing. This doesn't seem to cause any graphical issues. Notice how the correct size is reported immediately after the size that crashes the game.

  1. Not updating the Gui when the client temporarily reports an odd height
if (ySize < 0) {
	return;
}
  1. Forcing the Gui to render the last known valid height is another option
// Requires declaring a new variable at the top of RecipesGui.java

if (ySize < 0) {
	ySize = previousGuiHeight;
}

previousGuiHeight = ySize;

I've confirmed the issue using the environment that gradle sets up when building a NeoForge client on 1.21.1, because I initially discovered this issue while playing ATM10 on 1.21.1. The JDK I used was temurin 21, for both building and running the mod.

I have added some debugging options to the logfile to show what sizes it tries to render.

Crash Report

https://gist.github.com/TellyO3/16209849389afba0f92cd6e2e1542991

commented

I've done a bit more research and discovered that this doesn't just affect fullscreen mode, changing the size in windowed mode to something extreme will also crash the game. I have proposed a fix here, since there already was a minimum width to the RecipesGui I figured that adding a minimum height would also make sense.

I've tested this implementation with rescaling with Gui scales 1-5 and auto, and by losing and gaining focus causing a resolution change, neither of which causes a crash now. It might be possible to optimize the logic slightly, but I'll see if you agree with my solution first.