From 550b934ec916e784eb29b85151b1c3f24b16148c Mon Sep 17 00:00:00 2001 From: hexagon-recursion Date: Sat, 17 Aug 2024 23:58:33 +0300 Subject: [PATCH] Fix crash in FrameShowLimit --- colobot-base/src/graphics/engine/pyro.cpp | 4 ++-- colobot-base/src/level/robotmain.cpp | 9 +++++++-- colobot-base/src/level/robotmain.h | 2 +- colobot-base/src/object/old_object.cpp | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/colobot-base/src/graphics/engine/pyro.cpp b/colobot-base/src/graphics/engine/pyro.cpp index ac4862644..b79629b24 100644 --- a/colobot-base/src/graphics/engine/pyro.cpp +++ b/colobot-base/src/graphics/engine/pyro.cpp @@ -1583,7 +1583,7 @@ void CPyro::ExploStart() m_camera->SetType(CAM_TYPE_EXPLO); m_main->DeselectAll(); } - m_main->RemoveFromSelectionHistory(m_object); + m_main->CutObjectLink(m_object); for (int i = 0; i < OBJECTMAXPART; i++) { @@ -1656,7 +1656,7 @@ void CPyro::BurnStart() m_camera->SetType(CAM_TYPE_EXPLO); m_main->DeselectAll(); } - m_main->RemoveFromSelectionHistory(m_object); + m_main->CutObjectLink(m_object); for (int i = 0; i < OBJECTMAXPART; i++) { diff --git a/colobot-base/src/level/robotmain.cpp b/colobot-base/src/level/robotmain.cpp index 7e928497f..a8306f61d 100644 --- a/colobot-base/src/level/robotmain.cpp +++ b/colobot-base/src/level/robotmain.cpp @@ -2071,7 +2071,7 @@ bool CRobotMain::DestroySelectedObject() dynamic_cast(*obj).SetSelect(false); // deselects the object m_camera->SetType(Gfx::CAM_TYPE_EXPLO); DeselectAll(); - RemoveFromSelectionHistory(obj); + CutObjectLink(obj); return true; } @@ -5910,11 +5910,16 @@ CObject* CRobotMain::PopFromSelectionHistory() return obj; } -void CRobotMain::RemoveFromSelectionHistory(CObject* object) +void CRobotMain::CutObjectLink(CObject* object) { auto it = std::remove_if(m_selectionHistory.begin(), m_selectionHistory.end(), [object](const CObject* obj) { return obj == object; }); m_selectionHistory.erase(it, m_selectionHistory.end()); + + for (int i = 0; i < MAXSHOWLIMIT; i++) + { + if (m_showLimit[i].link == object) FlushShowLimit(i); + } } float CRobotMain::GetGlobalMagnifyDamage() diff --git a/colobot-base/src/level/robotmain.h b/colobot-base/src/level/robotmain.h index 3b339f9b6..98904c6fd 100644 --- a/colobot-base/src/level/robotmain.h +++ b/colobot-base/src/level/robotmain.h @@ -492,7 +492,7 @@ class CRobotMain : public CSingleton Error CanFactoryError(ObjectType type, int team); //@} - void RemoveFromSelectionHistory(CObject* object); + void CutObjectLink(CObject* object); //! Returns global magnifyDamage setting float GetGlobalMagnifyDamage(); diff --git a/colobot-base/src/object/old_object.cpp b/colobot-base/src/object/old_object.cpp index f6ec0dcc2..809bbd098 100644 --- a/colobot-base/src/object/old_object.cpp +++ b/colobot-base/src/object/old_object.cpp @@ -200,7 +200,7 @@ void COldObject::DeleteObject(bool bAll) { m_camera->SetControllingObject(nullptr); } - m_main->RemoveFromSelectionHistory(this); + m_main->CutObjectLink(this); if ( !bAll ) { @@ -596,7 +596,7 @@ void COldObject::DestroyObject(DestructionType type, CObject* killer) m_camera->SetType(Gfx::CAM_TYPE_EXPLO); m_main->DeselectAll(); } - m_main->RemoveFromSelectionHistory(this); + m_main->CutObjectLink(this); CScoreboard* scoreboard = m_main->GetScoreboard(); if (scoreboard)