From 1cdbc812ada2e41b34d4f77378b8cf1e58590e49 Mon Sep 17 00:00:00 2001 From: "seer-by-sentry[bot]" <157164994+seer-by-sentry[bot]@users.noreply.github.com> Date: Sun, 1 Mar 2026 17:10:28 +0000 Subject: [PATCH] Fix: Prevent null dereference in HLOD copy assignment --- .../Libraries/Source/WWVegas/WW3D2/hlod.cpp | 20 +++++++++++++------ .../Libraries/Source/WWVegas/WW3D2/hlod.cpp | 20 +++++++++++++------ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp index 4e8dc5d665e..00fe1d37836 100644 --- a/Generals/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp +++ b/Generals/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp @@ -1262,12 +1262,16 @@ HLodClass & HLodClass::operator = (const HLodClass & that) for (model = 0; model < that.Lod[lod].Count(); model++) { + if (that.Lod[lod][model].Model == nullptr) continue; + ModelNodeClass newnode; newnode.Model = that.Lod[lod][model].Model->Clone(); newnode.BoneIndex = that.Lod[lod][model].BoneIndex; - newnode.Model->Set_Container(this); - if (Is_In_Scene()) { - newnode.Model->Notify_Added(Scene); + if (newnode.Model != nullptr) { + newnode.Model->Set_Container(this); + if (Is_In_Scene()) { + newnode.Model->Notify_Added(Scene); + } } Lod[lod].Add(newnode); @@ -1277,12 +1281,16 @@ HLodClass & HLodClass::operator = (const HLodClass & that) AdditionalModels.Resize(that.AdditionalModels.Count()); for (model = 0; model < that.AdditionalModels.Count(); model++) { + if (that.AdditionalModels[model].Model == nullptr) continue; + ModelNodeClass newnode; newnode.Model = that.AdditionalModels[model].Model->Clone(); newnode.BoneIndex = that.AdditionalModels[model].BoneIndex; - newnode.Model->Set_Container(this); - if (Is_In_Scene()) { - newnode.Model->Notify_Added(Scene); + if (newnode.Model != nullptr) { + newnode.Model->Set_Container(this); + if (Is_In_Scene()) { + newnode.Model->Notify_Added(Scene); + } } AdditionalModels.Add(newnode); diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp index e65f7211d6e..17965944b0b 100644 --- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp +++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/hlod.cpp @@ -1262,12 +1262,16 @@ HLodClass & HLodClass::operator = (const HLodClass & that) for (model = 0; model < that.Lod[lod].Count(); model++) { + if (that.Lod[lod][model].Model == nullptr) continue; + ModelNodeClass newnode; newnode.Model = that.Lod[lod][model].Model->Clone(); newnode.BoneIndex = that.Lod[lod][model].BoneIndex; - newnode.Model->Set_Container(this); - if (Is_In_Scene()) { - newnode.Model->Notify_Added(Scene); + if (newnode.Model != nullptr) { + newnode.Model->Set_Container(this); + if (Is_In_Scene()) { + newnode.Model->Notify_Added(Scene); + } } Lod[lod].Add(newnode); @@ -1277,12 +1281,16 @@ HLodClass & HLodClass::operator = (const HLodClass & that) AdditionalModels.Resize(that.AdditionalModels.Count()); for (model = 0; model < that.AdditionalModels.Count(); model++) { + if (that.AdditionalModels[model].Model == nullptr) continue; + ModelNodeClass newnode; newnode.Model = that.AdditionalModels[model].Model->Clone(); newnode.BoneIndex = that.AdditionalModels[model].BoneIndex; - newnode.Model->Set_Container(this); - if (Is_In_Scene()) { - newnode.Model->Notify_Added(Scene); + if (newnode.Model != nullptr) { + newnode.Model->Set_Container(this); + if (Is_In_Scene()) { + newnode.Model->Notify_Added(Scene); + } } AdditionalModels.Add(newnode);