Maybe fix Mac crashing with sodium on world start?

This commit is contained in:
James Seibel
2026-02-12 07:27:11 -06:00
parent a758c0bb3f
commit 2d70388587
2 changed files with 30 additions and 2 deletions
@@ -410,6 +410,8 @@ public class ClientApi
*/
public void renderDeferredLodsForShaders() { this.renderLodLayer(true); }
public static long firstRenderTimeMs = 0;
private void renderLodLayer(boolean renderingDeferredLayer)
{
IProfilerWrapper profiler = MC_CLIENT.getProfiler();
@@ -529,7 +531,12 @@ public class ClientApi
//============//
///region
String validationMessage = renderParams.getValidationErrorMessage();
if (firstRenderTimeMs == 0)
{
firstRenderTimeMs = System.currentTimeMillis();
}
String validationMessage = renderParams.getValidationErrorMessage(firstRenderTimeMs);
if (validationMessage != null)
{
// store the error message so it can be seen on the F3 screen
@@ -4,6 +4,7 @@ import com.seibel.distanthorizons.api.enums.rendering.EDhApiRenderPass;
import com.seibel.distanthorizons.api.methods.events.sharedParameterObjects.DhApiRenderParam;
import com.seibel.distanthorizons.core.api.internal.SharedApi;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.jar.EPlatform;
import com.seibel.distanthorizons.core.level.IDhClientLevel;
import com.seibel.distanthorizons.core.render.RenderBufferHandler;
import com.seibel.distanthorizons.core.render.renderer.generic.GenericObjectRenderer;
@@ -27,6 +28,8 @@ public class RenderParams extends DhApiRenderParam
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
private static final IMinecraftRenderWrapper MC_RENDER = SingletonInjector.INSTANCE.get(IMinecraftRenderWrapper.class);
private static final long TIME_FOR_MAC_TO_FINISH_COMPILING_IN_MS = 5_000;
public IDhClientWorld dhClientWorld;
public IDhClientLevel dhClientLevel;
@@ -92,7 +95,7 @@ public class RenderParams extends DhApiRenderParam
* Should be called before rendering is done.
* @return a message if LODs shouldn't be rendered, null if the LODs can render
*/
public String getValidationErrorMessage()
public String getValidationErrorMessage(long firstRenderTimeMs)
{
// Note: all strings here should be constants to prevent String allocations
@@ -148,6 +151,24 @@ public class RenderParams extends DhApiRenderParam
}
// potential fix for a segfault when
// Sodium and DH are running together
if (EPlatform.get() == EPlatform.MACOS)
{
// Once MC starts rendering, wait a few seconds so
// MC/Sodium can finish their shader compiling before DH does its own.
// This will allow DH to compile its own shaders after Sodium finishes
// compiling it's own.
long nowMs = System.currentTimeMillis();
long firstAllowedRenderTimeMs = firstRenderTimeMs + TIME_FOR_MAC_TO_FINISH_COMPILING_IN_MS;
if (nowMs < firstAllowedRenderTimeMs)
{
return "Waiting for initial MC compile...";
}
}
return null;
}