Bewitchment

Bewitchment

7M Downloads

Weird crash on World load

tyra314 opened this issue ยท 4 comments

commented

After I updated to Bewitchment 1.16.5-5, I get a crash when I try to load a world.
The crash report references Pehkui, but if I use the previous Bewitchment version or start the pack without Bewitchment, there's no crash.

Here's a crash log

And here is the same issue at Pehkui

commented

#55
This issue was closed with the same error, the "solution" there did not work for me and I also posted my logs there, and in another issue. I have been tearing my hair out trying to figure out what the issue is, but it always comes back to this mod. I'll be watching to see if there's any ideas.
I know it is a conflict with Better End at least, but seems to be quite a few other mods too.

commented

Go to Virtuoel/Pehkui#46, I actually have no idea what this issue is. I've been trying to enable and disable random mods and it just happens to crash for absolutely no reason when completely unrelated mods are installed, and only if all of them are enabled.

commented

I think I found the underlying issue. And I guess you need to "fix" it in Bewitchment.

Pehkui requires a crude getClass dance to initialize its internal data structures. If the class loading sequence in Pekhui isn't correct, the registries are filled with entries that have null as keys. During world load, these null keys are mapped in a stream without a null check, which raises an NPE that ultimately crash the game.

Bewitchment, understandably, doesn't care about the class loading order of Pehkui during its initialization and only loads the classes it needs itself. Unfortunately, as the order in which the mods are initialized isn't defined to be in a particular order, there are mod configurations in which Bewitchment is loaded before Pehkui. Bewitchment partially loads the classes and therefore Pekhui isn't initialized in the correct order.

While I see all the bad things and don't like it one bit, the following patch mitigates the issue:

diff --git a/src/main/java/moriyashiine/bewitchment/common/Bewitchment.java b/src/main/java/moriyashiine/bewitchment/common/Bewitchment.java
index 998e2392..95594125 100644
--- a/src/main/java/moriyashiine/bewitchment/common/Bewitchment.java
+++ b/src/main/java/moriyashiine/bewitchment/common/Bewitchment.java
@@ -62,6 +62,9 @@ import net.minecraft.world.biome.Biome;
 import net.minecraft.world.explosion.Explosion;
 import top.theillusivec4.somnus.api.PlayerSleepEvents;
 import top.theillusivec4.somnus.api.WorldSleepEvents;
+import virtuoel.pehkui.api.ScaleModifier;
+import virtuoel.pehkui.api.ScaleRegistries;
+import virtuoel.pehkui.api.ScaleType;

 public class Bewitchment implements ModInitializer {
        public static final String MODID = "bewitchment";
@@ -217,6 +220,11 @@ public class Bewitchment implements ModInitializer {
                                });
                        }
                });
+
+               ScaleRegistries.SCALE_TYPES.getClass();
+               ScaleModifier.IDENTITY.getClass();
+               ScaleType.INVALID.getClass();
+
                BWScaleTypes.init();
                BWObjects.init();
                BWBlockEntityTypes.init();
commented

That's incredibly dumb and I can't believe you found that