diff --git a/src/main/java/me/jellysquid/mods/sodium/client/util/workarounds/Workarounds.java b/src/main/java/me/jellysquid/mods/sodium/client/util/workarounds/Workarounds.java index 646539d90c..d71b850789 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/util/workarounds/Workarounds.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/util/workarounds/Workarounds.java @@ -31,8 +31,8 @@ private static Set findNecessaryWorkarounds(List adapter.vendor() == GraphicsAdapterProbe.Vendor.NVIDIA)) { + if ((operatingSystem == Util.OperatingSystem.WINDOWS || operatingSystem == Util.OperatingSystem.LINUX) && + graphicsAdapters.stream().anyMatch(adapter -> adapter.vendor() == GraphicsAdapterProbe.Vendor.NVIDIA)) { workarounds.add(Reference.NVIDIA_BAD_DRIVER_SETTINGS); } @@ -69,6 +69,6 @@ public enum Reference { * Requesting a No Error Context causes a crash at startup when using a Wayland session. * GitHub Issue */ - NO_ERROR_CONTEXT_UNSUPPORTED + NO_ERROR_CONTEXT_UNSUPPORTED, } } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/util/workarounds/platform/NVIDIAWorkarounds.java b/src/main/java/me/jellysquid/mods/sodium/client/util/workarounds/platform/NVIDIAWorkarounds.java index d9f5730ccb..23519ab227 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/util/workarounds/platform/NVIDIAWorkarounds.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/util/workarounds/platform/NVIDIAWorkarounds.java @@ -178,13 +178,16 @@ public static void install() { return; } - if (Util.getOperatingSystem() != Util.OperatingSystem.WINDOWS) { - return; - } - LOGGER.info("Attempting to apply workarounds for the NVIDIA Graphics Driver..."); LOGGER.info("If the game crashes immediately after this point, please make a bug report: https://github.com/CaffeineMC/sodium-fabric/issues"); + if (Util.getOperatingSystem() == Util.OperatingSystem.LINUX) { + setLinuxDisableEnv(); + return; + } else if (Util.getOperatingSystem() != Util.OperatingSystem.WINDOWS) { + return; + } + try { ACTIVE_HOOK = new Hook(); ACTIVE_HOOK.install(); @@ -199,6 +202,18 @@ public static void install() { } } + public static void setLinuxDisableEnv() { + try (SharedLibrary sharedLibrary = Library.loadNative("me.jellyquid.mods.sodium", "libc.so.6")) { + long pfnSetenv = APIUtil.apiGetFunctionAddress(sharedLibrary, "setenv"); + try (var stack = MemoryStack.stackPush()) { + JNI.callPPI(MemoryUtil.memAddress0(stack.UTF8("__GL_THREADED_OPTIMIZATIONS")), MemoryUtil.memAddress0(stack.UTF8("0")), 1, pfnSetenv); + } + } catch (Throwable t) { + LOGGER.error("Failure while applying workarounds", t); + LOGGER.error("READ ME! The workarounds for the NVIDIA Graphics Driver did not apply correctly!"); + } + } + public static void uninstall() { if (ACTIVE_HOOK == null) { return;