Skip to content

fix shader ressource loading #3132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 1.21.1/stable
Choose a base branch
from

Conversation

coco875
Copy link

@coco875 coco875 commented Apr 30, 2025

this modification fix error with nvidium when loaded through connector

@coco875
Copy link
Author

coco875 commented Apr 30, 2025

for more context, this is the message of Su5eD https://ptb.discord.com/channels/1141048834177388746/1141069780225380523/1177749063609892924 it's was for embeddium in 1.20.1

@jellysquid3
Copy link
Member

I don't have access to the mentioned Discord channel, can you please explain why this is necessary?

@coco875
Copy link
Author

coco875 commented Apr 30, 2025

I've investigated Nvidium compatibility and to my surprise, it seems to actually work? That is, except for one small problem which requires a change in embeddium to be fixed.
Embeddium uses the class object for locating resources, which behaves differently in a modular environment. Using this method, SJH's classloader will only search for resources in the caller's module, making it impossible to load shaders from other mods, including nvidium. (not sure if any of this should be used by addons though).
The fix is quite simple - moving getResourceAsStream to be called on the original class's classloader instead, which searches all loaded mods for the specified resource.

@@ -25,7 +25,7 @@
     public static String getShaderSource(Identifier name) {
         String path = String.format("/assets/%s/shaders/%s", name.getNamespace(), name.getPath());
 
-        try (InputStream in = ShaderLoader.class.getResourceAsStream(path)) {
+        try (InputStream in = ShaderLoader.class.getClassLoader().getResourceAsStream(path)) {
             if (in == null) {
                 throw new RuntimeException("Shader not found: " + path);
             }

the original message, I hope it help

@douira
Copy link
Collaborator

douira commented Apr 30, 2025

There's already a compatible nvidium beta. Why is this necessary?

@coco875
Copy link
Author

coco875 commented Apr 30, 2025

because it crash because of java.lang.RuntimeException: Shader not found: /assets/nvidium/shaders/terrain/task.glsl (the full log: https://mclo.gs/kVbGl1P) (I use the fork https://github.com/drouarb/nvidium) and I use neoforge, not fabric

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants