From f0645c59931f56415999b9befe473f5af642a5ce Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 19 Apr 2022 22:08:34 -0400 Subject: fix null reference when adding new layers in a map patch --- src/SMAPI/Framework/Content/AssetDataForMap.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/SMAPI/Framework/Content/AssetDataForMap.cs') diff --git a/src/SMAPI/Framework/Content/AssetDataForMap.cs b/src/SMAPI/Framework/Content/AssetDataForMap.cs index 8674461e..b8722ead 100644 --- a/src/SMAPI/Framework/Content/AssetDataForMap.cs +++ b/src/SMAPI/Framework/Content/AssetDataForMap.cs @@ -99,8 +99,15 @@ namespace StardewModdingAPI.Framework.Content } // get target layers - IDictionary sourceToTargetLayers = source.Layers.ToDictionary(p => p, p => target.GetLayer(p.Id)); - HashSet orphanedTargetLayers = new HashSet(target.Layers.Except(sourceToTargetLayers.Values)); + Dictionary sourceToTargetLayers = + ( + from sourceLayer in source.Layers + let targetLayer = target.GetLayer(sourceLayer.Id) + where targetLayer != null + select (sourceLayer, targetLayer) + ) + .ToDictionary(p => p.sourceLayer, p => p.targetLayer); + HashSet orphanedTargetLayers = new(target.Layers.Except(sourceToTargetLayers.Values)); // apply tiles bool replaceAll = patchMode == PatchMapMode.Replace; -- cgit