sp614x / optifine

1.8k stars 418 forks source link

[Mipmaps/AWT?] Mipmaps unnessesarily uses a java.awt class, causing hangs on macOS #4980

Open magneticflux- opened 3 years ago

magneticflux- commented 3 years ago

Description of Issue

A non-headless environment is required to access the Desktop.getDesktop() API for user interaction. If java.awt.headless=false is set and AWT is initialized on macOS, the JVM hangs. AWT is accidentally initialized by OptiFine because the Mipmaps class uses java.awt.Dimension as a simple integer 2-tuple. This class has a static initializer block that runs JNI code if the environment is not headless.

Steps to Reproduce

Run OptiFine on macOS with -Djava.awt.headless=false

OptiFine Version

At least 1.16.3, probably any.

Installation Method

Shouldn't matter, but OptiFabric was used.

Logs

All the logs I've seen are normal, they just hang after logging about generating mipmaps.

Additional Information

Discovered here: https://github.com/magneticflux-/fabric-mumblelink-mod/issues/32

This should be easily fixable by creating a custom "Dimension" class that contains width and height fields and swapping the import statement. In fact, a StackOverflow post from 2013 says exactly this: https://stackoverflow.com/a/17389889/9073728

Chocohead commented 3 years ago

There's already the PairInt class for passing two numbers around which could be used instead of Dimension too, no new class necessary.