Fusion (Connected Textures)

Fusion (Connected Textures)

40M Downloads

[Crash] [1.21.8] Crashes with mods that use Puzzles Lib's `BlockStateResolverContextNeoForgeImpl`

Fuzss opened this issue · 3 comments

commented

Version Info

Connected Glass 1.1.14 (connectedglass)
Easy Magic 21.8.0 (easymagic)
Fusion 1.2.9 (fusion)
Minecraft 1.21.8 (minecraft)
NeoForge 21.8.4-beta (neoforge)
Puzzles Lib 21.8.0 (puzzleslib)
SuperMartijn642's Core Lib 1.1.18+c (supermartijn642corelib)

What mod loader are you using?: NeoForge

Are you using OptiFine: No

Steps to Reproduce

Launch the game with the listed mods installed.

Crash report (~/logs/latest.log)

latest.log: https://mclo.gs/5189hNn
crash report: https://mclo.gs/4XBb8pq

The crash report is useless, the actual error is in the latest.log.

commented

I did some code analysis and I've possibly found the issue, which ended up being a vanilla problem.

As you can see from the latest.log the actual problem is here:

Caused by: java.lang.UnsupportedOperationException
	at java.base/java.util.ImmutableCollections.uoe(ImmutableCollections.java:142) ~[?:?]
	at java.base/java.util.ImmutableCollections$AbstractImmutableMap.put(ImmutableCollections.java:1079) ~[?:?]
	at TRANSFORMER/[email protected]/com.supermartijn642.fusion.model.modifiers.block.BlockModelModifierReloadListener.applyOverlays(BlockModelModifierReloadListener.java:65) ~[?:?]
	at TRANSFORMER/[email protected]/net.minecraft.client.resources.model.ModelBakery.mdef440f$fusion$lambda$applyBlockModelOverlays$0$3(ModelBakery.java:1036) ~[?:?]
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[?:?]

So how does BakingResult::blockStateModels end up as an immutable map?
The problem is the call to ParallelMapTransform::schedule in ModelBakery::bakeModels. That method creates a mutable map for an input map of size > 1, but an immutable map for input map size <= 1.

The input map is empty in the first place due to my usage of a custom ModelBakery for a system I developed on top of ModelEvent.ModifyBakingResult for supporting Fabric's BlockStateResolvers, see here: https://github.com/Fuzss/puzzleslib/blob/46a42b69438291547b1c8ff63d905cd72f9b2616/1.21.8/NeoForge/src/main/java/fuzs/puzzleslib/neoforge/impl/client/core/context/BlockStateResolverContextNeoForgeImpl.java#L86

I don't think there is anything that can change there to help the issue.

commented

Thanks a ton for looking into it and the explanation! I have been staring at Minecraft's code and Puzzles Lib's code for nearly an hour and could just not figure out how my mixin was getting called from within the NeoForge ModifyBakingResult event and how BakingResult::blockStateModels would be immutable only with mods using Puzzles Lib installed 😅
A custom ModelBakery and ParallelMapTransform::schedule returning an immutable map depending on the entry count does indeed explain that 🙃

I will probably just add a check to see whether the BakingResult::blockStateModels is mutable and if not, build a new immutable map. I might also ignore other ModelBakerys, as it is probably not ideal that Fusion is potentially overwriting models in those.

commented

Should be fixed now in the new Fusion update. Thanks for the help!