Skip to content

Commit

Permalink
fix crash when the vr fabulous shader fails to compile
Browse files Browse the repository at this point in the history
  • Loading branch information
fayer3 committed Dec 18, 2024
1 parent ce1c1a1 commit 702ae8e
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,14 @@ public void setupRenderConfiguration() throws Exception {
this.reinitFrameBuffers("gfx setting change");
}

if (minecraft.options.graphicsMode().get() == GraphicsStatus.FABULOUS &&
minecraft.getShaderManager().getProgram(VRShaders.vrTransparency) == null) {
minecraft.gui.getChat().addMessage(Component.translatable("vivecraft.messages.fabulousFailed"));
minecraft.options.graphicsMode().set(GraphicsStatus.FAST);
minecraft.levelRenderer.allChanged();
this.reinitFrameBuffers("fabulous missing");
}

if ((this.resizeFrameBuffers || this.reinitFramebuffers) &&
((WindowExtension) (Object) Minecraft.getInstance().getWindow()).vivecraft$getActualScreenWidth() != 0 &&
((WindowExtension) (Object) Minecraft.getInstance().getWindow()).vivecraft$getActualScreenHeight() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public class VRShaders {
ResourceLocation.fromNamespaceAndPath("vivecraft", "core/rendertype_end_gateway_vr"),
DefaultVertexFormat.POSITION, ShaderDefines.EMPTY);

public static final ShaderProgram vrTransparency = new ShaderProgram(
ResourceLocation.fromNamespaceAndPath("vivecraft", "post/vrtransparency"),
DefaultVertexFormat.POSITION, ShaderDefines.EMPTY);

private VRShaders() {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.vivecraft.mixin.client.renderer;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.renderer.ShaderManager;
import net.minecraft.client.renderer.ShaderProgram;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.vivecraft.client_vr.render.VRShaders;
import org.vivecraft.client_vr.settings.VRSettings;

import java.util.Map;
import java.util.Optional;

@Mixin(ShaderManager.class)
public class ShaderManagerMixin {

@WrapOperation(method = "apply(Lnet/minecraft/client/renderer/ShaderManager$Configs;Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/util/profiling/ProfilerFiller;)V", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", ordinal = 1))
private Object vivecraft$letTransparencyFail(Map instance, Object k, Object v, Operation<Object> original, @Local ShaderManager.CompilationCache compilationCache) {
if (((ShaderProgram) k).configId().equals(VRShaders.vrTransparency.configId())) {
// let vrtransparency fail, some gpus don't support the 18 samplers we need
VRSettings.logger.error("Vivecraft: Failed to compile 'post/vrtransparency' fabulous graphics will not be available in VR.", (ShaderManager.CompilationException) v);
compilationCache.programs.put((ShaderProgram) k, Optional.empty());
return null;
}
return original.call(instance, k, v);
}
}
1 change: 1 addition & 0 deletions common/src/main/resources/assets/vivecraft/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@
"vivecraft.messages.stencil": "[Vivecraft] Ein anderer Mod verwendet den Schablonen Puffer, wenn Sie Grafikfehler bemerken, versuchen Sie die Augenschablone in folgendem Menü zu deaktivieren: %s\nSie können diese Nachricht in folgendem Menü deaktivieren: %s",
"vivecraft.messages.3options": "%s > %s > %s",
"vivecraft.messages.openSettings": "Klicken um die Einstellungen zu öffnen.",
"vivecraft.messages.fabulousFailed": "§cFabelhaft VR Shader konnte nicht kompiliert werden, prüfe den Log für den kompletten Fehler.",
"vivecraft.message.kofi": "Unterstütze uns auf Ko-Fi",
"vivecraft.message.overriddenbyserver": "§6Einstellung überschrieben vom Server.§r\n",
"vivecraft.message.limitedbyserver": "§6Einstellungsbereich vom Server limitiert (%s - %s)§r\n",
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/assets/vivecraft/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@
"vivecraft.messages.stencil": "[Vivecraft] A different mod uses the stencil buffer, if you run into weird rendering issues, try disabling the Eye Stencil in: %s\nYou can disable this message in: %s",
"vivecraft.messages.3options": "%s > %s > %s",
"vivecraft.messages.openSettings": "Click to open settings",
"vivecraft.messages.fabulousFailed": "§cFabulous VR shader failed to compile, check the log for the full error.",
"vivecraft.message.kofi": "Support us on Ko-Fi",
"vivecraft.message.overriddenbyserver": "§6Setting overridden by server.§r\n",
"vivecraft.message.limitedbyserver": "§6Setting range limited by server (%s - %s)§r\n",
Expand Down
4 changes: 4 additions & 0 deletions common/src/main/resources/vivecraft.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ accessible field net/minecraft/server/network/ServerGamePacketListenerImpl above
# to render the camera widget with dispaly
accessible field net/minecraft/client/renderer/item/ItemStackRenderState layers [Lnet/minecraft/client/renderer/item/ItemStackRenderState$LayerRenderState;
accessible field net/minecraft/client/renderer/item/ItemStackRenderState$LayerRenderState model Lnet/minecraft/client/resources/model/BakedModel;

# to let the vr transparancy shader fail to compile
accessible class net/minecraft/client/renderer/ShaderManager$CompilationCache
accessible field net/minecraft/client/renderer/ShaderManager$CompilationCache programs Ljava/util/Map;
1 change: 1 addition & 0 deletions common/src/main/resources/vivecraft.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"client.player.AbstractClientPlayerMixin",
"client.renderer.ItemBlockRenderTypesMixin",
"client.renderer.RenderStateShardAccessor",
"client.renderer.ShaderManagerMixin",
"client.renderer.block.LiquidBlockRendererMixin",
"client.renderer.entity.ArmedEntityRenderStateMixin",
"client.renderer.entity.EntityRenderDispatcherMixin",
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minecraft_version=1.21.4
enabled_platforms=fabric,forge,neoforge

archives_base_name=vivecraft
mod_version=1.1.14-b3
mod_version=1.1.14-b4
maven_group=org.vivecraft

architectury_version=15.0.1
Expand Down

0 comments on commit 702ae8e

Please sign in to comment.