Skip to content

Commit

Permalink
Fix streaming crash (#4030)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij authored Feb 17, 2025
1 parent 839f328 commit 003b001
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions Client/mods/deathmatch/logic/CClientStreamer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand All @@ -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)
{
Expand All @@ -199,7 +203,7 @@ void CClientStreamer::SetDimension(unsigned short usDimension)
{
iter++;
}
}
} while (!isLast);
}

CClientStreamSectorRow* CClientStreamer::FindOrCreateRow(CVector& vecPosition, CClientStreamSectorRow* pSurrounding)
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand All @@ -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<CClientVehicle>(pElement);
Expand Down Expand Up @@ -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))
{
Expand All @@ -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);
}

Expand Down

0 comments on commit 003b001

Please # to comment.