From 4e18be80eacccc938f622d6ac868741c050fca4b Mon Sep 17 00:00:00 2001 From: ontrigger Date: Sat, 28 Aug 2021 01:35:23 +0300 Subject: [PATCH] fixed compat issue with rune magic caused by prefab processors not expecting the piece component to be destroyed --- .../Patches/ObjectPooling/ObjectPoolingPatch.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ValheimPerformanceOptimizations/Patches/ObjectPooling/ObjectPoolingPatch.cs b/ValheimPerformanceOptimizations/Patches/ObjectPooling/ObjectPoolingPatch.cs index 499eb5a..def3508 100644 --- a/ValheimPerformanceOptimizations/Patches/ObjectPooling/ObjectPoolingPatch.cs +++ b/ValheimPerformanceOptimizations/Patches/ObjectPooling/ObjectPoolingPatch.cs @@ -80,9 +80,9 @@ public static void Postfix(ZoneSystem __instance) // skip prefabs with multiple mods for now if (prefab.GetComponentsInChildren().Length > 1) { continue; } - + // skip viewless prefabs - if (prefab.GetComponentInChildren() == null) {continue;} + if (prefab.GetComponentInChildren() == null) { continue; } ExtractPrefabProcessors(prefab); @@ -94,7 +94,6 @@ public static void Postfix(ZoneSystem __instance) ZNetView.StartGhostInit(); CreateZoneSystemPool(maxObjectsByVegetation); - CreateZNetScenePool(maxObjectsByVegetation); ZNetView.FinishGhostInit(); } @@ -203,6 +202,7 @@ private static void WearNTearDisabledProcessor(ComponentCache componentCache) private static void PieceEnabledProcessor(ComponentCache componentCache) { var piece = componentCache.Piece; + if (piece == null) { return; } Piece.m_allPieces.Add(piece); piece.m_myListIndex = Piece.m_allPieces.Count - 1; @@ -211,6 +211,9 @@ private static void PieceEnabledProcessor(ComponentCache componentCache) private static void PieceDisabledProcessor(ComponentCache componentCache) { + // RuneMagic destroys the piece component on some rocks causing the unchecked code to crash + if (componentCache.Piece == null) { return; } + componentCache.Piece.OnDestroy(); }