From 071e2dc52453ce2161a8ee4467592818140de6d2 Mon Sep 17 00:00:00 2001 From: Christian Date: Wed, 15 Aug 2012 20:05:12 -0400 Subject: [PATCH] Handle the case where a mod tries to do something stateful during constructor phase, and log a big fat message about it. Don't do it! --- .../cpw/mods/fml/common/LoadController.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/common/cpw/mods/fml/common/LoadController.java b/common/cpw/mods/fml/common/LoadController.java index e7e0664799..533e247ecb 100644 --- a/common/cpw/mods/fml/common/LoadController.java +++ b/common/cpw/mods/fml/common/LoadController.java @@ -117,7 +117,7 @@ public class LoadController { if (stateEvent instanceof FMLPreInitializationEvent) { - buildModObjectList(); + modObjectList = buildModObjectList(); } for (Map.Entry entry : eventChannels.entrySet()) { @@ -138,17 +138,25 @@ public class LoadController } } - public void buildModObjectList() + public ImmutableBiMap buildModObjectList() { ImmutableBiMap.Builder builder = ImmutableBiMap.builder(); for (ModContainer mc : activeModList) { - if (!mc.isImmutable()) + if (!mc.isImmutable() && mc.getMod()!=null) { builder.put(mc, mc.getMod()); } + if (mc.getMod()==null) + { + FMLLog.severe("There is a severe problem with %s - it appears not to have constructed correctly", mc.getModId()); + if (state != LoaderState.CONSTRUCTING) + { + this.errorOccurred(mc, new RuntimeException()); + } + } } - modObjectList = builder.build(); + return builder.build(); } public void errorOccurred(ModContainer modContainer, Throwable exception) @@ -191,6 +199,11 @@ public class LoadController public BiMap getModObjectList() { + if (modObjectList == null) + { + FMLLog.severe("Detected an attempt by a mod %s to perform game activity during mod construction. This is a serious programming error.", activeContainer); + return buildModObjectList(); + } return ImmutableBiMap.copyOf(modObjectList); }