Skip to content
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

(Forge) Mod loading fails in a development environment due to misuse of DistExecutor#safeRunWhenOn #79

Closed
RedstoneDubstep opened this issue May 17, 2022 · 0 comments

Comments

@RedstoneDubstep
Copy link

In BetterF3Forge#init, two instances of the method DistExecutor#safeRunWhenOn are used to validate that this mod runs when loaded on the client dist, or to send a warning if it is loaded on the server. By using a double lambda for the Supplier<SafeRunnable> argument, the contract of SafeReferent is violated. The correct usage of safeRunWhenOn and other safe methods of DistExecutor is to supply a method reference, as seen in the documentation of DistExecutor$SafeReferent, instead of supplying a lambda expression. When calling safeRunWhenOn in this wrong manner, it gets detected by DistExecutor#validateSafeReferent, which throws a RuntimeException, therefore preventing this mod from loading and causing a crash in the process.

A suggested fix would be to move the supplied lambdas to their own methods in another class (an example for this can be found in the documentation of DistExecutor$SafeReferent) and referencing these in the supplier. Another, more simple solution would be to switch out the calls to DistExecutor with an if (FMLEnvironment.dist == Dist.CLIENT) check, although that solution removes some of the sanity checks of DistExecutor, potentially resulting in attempted classloading of classes not present on the desired dist.

The issue does not occur in production due to a check in DistExecutor#validateSafeReferent, however it affects mod developers using this mod as a dependency (the mods.toml file of this mod's jar needs to be removed after every dependency refresh to prevent this mod from preventing all mod loading in dev). As such, this issue is not game-breaking on the user side, but a fix would still be appreciated by developers working with this mod.

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

No branches or pull requests

1 participant