From a671178dba4496d33f967eef58af586b5274a690 Mon Sep 17 00:00:00 2001 From: Uladzislau Nikalayevich Date: Mon, 17 Feb 2025 12:37:06 +0300 Subject: [PATCH] Fix streaming crash --- .../mods/deathmatch/logic/CClientStreamer.cpp | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientStreamer.cpp b/Client/mods/deathmatch/logic/CClientStreamer.cpp index b45632002f3..cf9f4e74fc1 100644 --- a/Client/mods/deathmatch/logic/CClientStreamer.cpp +++ b/Client/mods/deathmatch/logic/CClientStreamer.cpp @@ -173,6 +173,8 @@ void CClientStreamer::SetDimension(unsigned short usDimension) if (element->IsStreamedIn()) m_ToStreamOut.push_back(element); + else if (sector->IsActivated()) + m_ActiveElements.remove(element); } } } @@ -186,9 +188,11 @@ void CClientStreamer::SetDimension(unsigned short usDimension) return; auto iter = m_outsideCurrentDimensionElements.begin(); - - while (*iter != lastOutsideElement) + bool isLast = false; + do { + isLast = *iter == lastOutsideElement; + CClientStreamElement* element = *iter; if (element->GetDimension() == usDimension) { @@ -199,7 +203,7 @@ void CClientStreamer::SetDimension(unsigned short usDimension) { iter++; } - } + } while (!isLast); } CClientStreamSectorRow* CClientStreamer::FindOrCreateRow(CVector& vecPosition, CClientStreamSectorRow* pSurrounding) @@ -331,7 +335,10 @@ void CClientStreamer::AddElement(CClientStreamElement* pElement) void CClientStreamer::RemoveElement(CClientStreamElement* pElement) { if (pElement->GetStreamSector()) + { RemoveElementFromSectors(pElement); + m_ActiveElements.remove(pElement); + } else m_outsideCurrentDimensionElements.remove(pElement); } @@ -419,6 +426,10 @@ void CClientStreamer::Restream(bool bMovedFar) // Stream out 1 of them per frame pElement->InternalStreamOut(); iMaxOut--; + + CClientStreamSector* streamSector = pElement->GetStreamSector(); + if (!streamSector || !streamSector->IsActivated() || !ShouldElementBeVisibleInCurrentDimension(pElement)) + m_ActiveElements.remove(pElement); } m_ToStreamOut.remove(pElement); @@ -442,6 +453,12 @@ void CClientStreamer::Restream(bool bMovedFar) // Is this element streamed in? if (pElement->IsStreamedIn()) { + if (!ShouldElementBeVisibleInCurrentDimension(pElement)) + { + m_ToStreamOut.push_back(pElement); + continue; + } + if (IS_VEHICLE(pElement)) { CClientVehicle* pVehicle = DynamicCast(pElement); @@ -701,10 +718,6 @@ void CClientStreamer::OnElementEnterSector(CClientStreamElement* pElement, CClie } else { - // Should we deactivate the element? - if (pPreviousSector && pPreviousSector->IsActivated()) - m_ActiveElements.remove(pElement); - // Should we activate this sector? if (pSector->IsExtra() && (m_pSector->IsMySurroundingSector(pSector) || m_pSector == pSector)) { @@ -713,17 +726,19 @@ void CClientStreamer::OnElementEnterSector(CClientStreamElement* pElement, CClie } // If we're in a deactivated sector and streamed in, stream us out else if (pElement->IsStreamedIn()) - { m_ToStreamOut.push_back(pElement); - } + else if (pPreviousSector && pPreviousSector->IsActivated()) + m_ActiveElements.remove(pElement); } } - else if (pPreviousSector && pPreviousSector->IsActivated()) + else { - // The element was removed from sectors. - // Remove it from active elements too. - m_ActiveElements.remove(pElement); + if (pElement->IsStreamedIn()) + m_ToStreamOut.push_back(pElement); + else if (pPreviousSector && pPreviousSector->IsActivated()) + m_ActiveElements.remove(pElement); } + pElement->SetStreamSector(pSector); }