From 9e2e2221cb34c1469a48e4f089a05af3b7d7fb67 Mon Sep 17 00:00:00 2001
From: MaxED <j.maxed@gmail.com>
Date: Mon, 29 Aug 2016 21:44:40 +0000
Subject: [PATCH] Fixed, Randomize things mode: fixed a crash when trying to
 move things, which were initially outside of sector boundary when using Hexen
 or UDMF map format.

---
 .../BuilderEffects/Interface/JitterThingsForm.cs     | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/Source/Plugins/BuilderEffects/Interface/JitterThingsForm.cs b/Source/Plugins/BuilderEffects/Interface/JitterThingsForm.cs
index 8db130425..ef9ce528c 100644
--- a/Source/Plugins/BuilderEffects/Interface/JitterThingsForm.cs
+++ b/Source/Plugins/BuilderEffects/Interface/JitterThingsForm.cs
@@ -128,11 +128,12 @@ namespace CodeImp.DoomBuilder.BuilderEffects
 				if(General.Map.FormatInterface.HasThingHeight) 
 				{
 					if(t.Sector == null) t.DetermineSector();
-					if(t.Sector == null) continue;
-
-					d.SectorHeight = Math.Max(0, t.Sector.CeilHeight - (int)t.Height - t.Sector.FloorHeight);
-					if(MaxSafeHeightDistance < d.SectorHeight) MaxSafeHeightDistance = d.SectorHeight;
-					d.ZOffset = (int)t.Position.z;
+					if(t.Sector != null)
+					{
+						d.SectorHeight = Math.Max(0, t.Sector.CeilHeight - (int)t.Height - t.Sector.FloorHeight);
+						if(MaxSafeHeightDistance < d.SectorHeight) MaxSafeHeightDistance = d.SectorHeight;
+						d.ZOffset = (int)t.Position.z;
+					}
 				}
 
 				thingData.Add(d);
@@ -257,6 +258,7 @@ namespace CodeImp.DoomBuilder.BuilderEffects
 		{
 			for(int i = 0; i < selection.Count; i++) 
 			{
+				if(thingData[i].SectorHeight == 0) continue;
 				int curAmmount = Math.Min(thingData[i].SectorHeight, Math.Max(0, thingData[i].ZOffset + ammount));
 				selection[i].Move(selection[i].Position.x, selection[i].Position.y, curAmmount * thingData[i].JitterHeight);
 			}
-- 
GitLab