From 0b93ea02f6e765d3f4deedd493bc3e4cb0aeba15 Mon Sep 17 00:00:00 2001
From: Dave Corley <smokydave@icloud.com>
Date: Thu, 16 May 2024 02:14:51 -0500
Subject: [PATCH] CLEANUP(CS): Do heightData check in actual implementation,
 revert accidental change to land condition order

---
 apps/opencs/view/render/cell.cpp           | 2 +-
 apps/opencs/view/render/terrainstorage.cpp | 2 ++
 components/esmterrain/storage.cpp          | 2 +-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/apps/opencs/view/render/cell.cpp b/apps/opencs/view/render/cell.cpp
index 0cabf5dcd5..3d3b82acf8 100644
--- a/apps/opencs/view/render/cell.cpp
+++ b/apps/opencs/view/render/cell.cpp
@@ -120,7 +120,7 @@ bool CSVRender::Cell::addObjects(int start, int end)
 
 void CSVRender::Cell::updateLand()
 {
-    if (mLandDeleted || !mUpdateLand)
+    if (!mUpdateLand || mLandDeleted)
         return;
 
     mUpdateLand = false;
diff --git a/apps/opencs/view/render/terrainstorage.cpp b/apps/opencs/view/render/terrainstorage.cpp
index 5d2a4874c8..16467f8255 100644
--- a/apps/opencs/view/render/terrainstorage.cpp
+++ b/apps/opencs/view/render/terrainstorage.cpp
@@ -154,6 +154,8 @@ namespace CSVRender
 
     void TerrainStorage::adjustColor(int col, int row, const ESM::LandData* heightData, osg::Vec4ub& color) const
     {
+        if (!heightData)
+            return;
         // Highlight broken height changes
         int heightWarningLimit = 1024;
         if (((col > 0 && row > 0) && leftOrUpIsOverTheLimit(col, row, heightWarningLimit, heightData->getHeights()))
diff --git a/components/esmterrain/storage.cpp b/components/esmterrain/storage.cpp
index edcddd3c67..bb44d836de 100644
--- a/components/esmterrain/storage.cpp
+++ b/components/esmterrain/storage.cpp
@@ -346,7 +346,7 @@ namespace ESMTerrain
                     color[i] = colourData->getColors()[srcArrayIndex + i];
 
             // Does nothing by default, override in OpenMW-CS
-            if (alteration && heightData != nullptr)
+            if (alteration)
                 adjustColor(col, row, heightData, color);
 
             // Unlike normals, colors mostly connect seamlessly between cells, but not always...