From 69a7806ad1d0b4cb344df8979817e5564febfda3 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 13 Dec 2022 00:26:11 +0000 Subject: [PATCH] Try a little harder to parse skins when they're not yet uploaded. Should fix ponies randomly appearing as humans early in-game --- .../client/util/render/NativeUtil.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/minelittlepony/client/util/render/NativeUtil.java b/src/main/java/com/minelittlepony/client/util/render/NativeUtil.java index 4099fe6c..54a51cd1 100644 --- a/src/main/java/com/minelittlepony/client/util/render/NativeUtil.java +++ b/src/main/java/com/minelittlepony/client/util/render/NativeUtil.java @@ -9,6 +9,8 @@ import com.mojang.blaze3d.systems.RenderSystem; import java.util.HashMap; import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import static com.mojang.blaze3d.platform.GlStateManager._getTexLevelParameter; @@ -92,9 +94,13 @@ public class NativeUtil { } public static void parseImage(Identifier resource, Consumer consumer, Consumer fail) { + parseImage(resource, consumer, fail, 0); + } + + private static void parseImage(Identifier resource, Consumer consumer, Consumer fail, int attempt) { try { if (!RenderSystem.isOnRenderThread()) { - RenderSystem.recordRenderCall(() -> parseImage(resource, consumer, fail)); + RenderSystem.recordRenderCall(() -> parseImage(resource, consumer, fail, attempt)); return; } @@ -112,7 +118,13 @@ public class NativeUtil { int height = _getTexLevelParameter(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT); if (width * height == 0) { - throw new IllegalStateException("GL texture not uploaded yet: " + resource); + if (attempt < 3) { + CompletableFuture.delayedExecutor(500, TimeUnit.MILLISECONDS, mc).execute(() -> { + parseImage(resource, consumer, fail, attempt + 1); + }); + } else { + throw new IllegalStateException("GL texture not uploaded yet: " + resource + " Parse failed 3/3 attempts"); + } } try (NativeImage image = new NativeImage(InternalFormat.valueOf(format).getClassification(), width, height, false)) {