Skip to content

Fix streaming crash #4030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading