Fix injection point for CoreShaderRegistrationCallback #3521
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relevant issue: #3230
From 1.20.1(?) to 1.20.4, the injection point for the CoreShaderRegistrationCallback event has been broken: it triggers every time vanilla registers a core shader, rather than once during the shader reload cycle. In practice, this means if you rely on the event for loading shaders and use the event as modeled in the test suite, your shader is parsed/validated about 60 times per reload. An extra implication of this is that if your shader has any unused fields, it will spam console ~60 times telling you to remove it (compared to a single warning per reload, which is what happens in a vanilla environment).
I removed the slice in favor of injecting at the first add call. A potential adjustment might be injecting at the last add call (to load modded shaders after vanilla shaders), but I'm not sure how to hit that inject point without leaving the try/catch block.
Testing / Replicating
fabric/fabric-rendering-v1/src/testmodClient/java/net/fabricmc/fabric/test/rendering/client/HudAndShaderTest.java
Lines 45 to 49 in a462da6
Place a print statement in this callback, or register a shader that will intentionally print a warning (such as one with an unused uniform). The print/warning will log approximately 60 times, once per vanilla core shader registration. The callback should only be triggered once, which is what happens after this patch is applied.
Thank you in advance for reviews and/or change requests! 馃挆