[#12687] NPE in ItemModule.getFlowRate() after a data patch resizes content arrays
自动翻译暂时不可用
本帖暂时展示 GitHub 原始内容。
Build
160.4
Issue
After a data patch adds or removes content, ItemModule.getFlowRate() throws:
java.lang.NullPointerException: Cannot load from float array because "mindustry.world.modules.ItemModule.displayFlow" is null
at mindustry.world.modules.ItemModule.getFlowRate(ItemModule.java:100)Cause
DataPatcher.fixContentArrays() calls ItemModule.empty.checkArrayCapacity(size), which resets the shared static flow caches:
cacheFlow = null;
cacheSums = null;
displayFlow = null;
flow = null;cacheFlow / cacheSums / displayFlow are static, but flow is per-instance, and fixContentArrays() only calls checkArrayCapacity on world buildings when the editor is open. Every other existing module therefore keeps a non-null flow while displayFlow is null, so the next getFlowRate() on it (vanilla hover flow display, mods reading flow rates) dereferences null.
Suggested fix
Make getFlowRate() null-safe (LiquidModule.getFlowRate() has the same issue):
return flow == null || displayFlow == null ? -1f : displayFlow[item.id] * 60;or clear flow on all world buildings in fixContentArrays() even when the editor is not shown.
由 MDT GitHub 同步机器人自动同步。