From 43bbd7d6713e3373a07e3f441c1c808fd838e1ea Mon Sep 17 00:00:00 2001 From: wraitii Date: Sat, 7 Sep 2019 14:41:53 +0000 Subject: [PATCH] Check only that the destruction queue contains no non-local entity when serializing the game state. Local entities being in the destruction queue when serialising is not an issue since those should not affect the simulation anyways. This stops the game from crashing in some rare situations. Fixes #4616 Differential Revision: https://code.wildfiregames.com/D1738 This was SVN commit r22865. --- .../simulation2/system/ComponentManagerSerialization.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/simulation2/system/ComponentManagerSerialization.cpp b/source/simulation2/system/ComponentManagerSerialization.cpp index 661124cc87..4248509e73 100644 --- a/source/simulation2/system/ComponentManagerSerialization.cpp +++ b/source/simulation2/system/ComponentManagerSerialization.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2019 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -181,9 +181,10 @@ bool CComponentManager::SerializeState(std::ostream& stream) const { CStdSerializer serializer(m_ScriptInterface, stream); - // We don't serialize the destruction queue, since we'd have to be careful to skip local entities etc - // and it's (hopefully) easier to just expect callers to flush the queue before serializing - ENSURE(m_DestructionQueue.empty()); + // We don't serialize the destruction queue, since we'd have to be careful to skip local entities etc. + // This means we cannot have non-local entities in the destruction queue at this point. + ENSURE(m_DestructionQueue.empty() || std::find_if(m_DestructionQueue.begin(), m_DestructionQueue.end(), + [](entity_id_t ent) { return !ENTITY_IS_LOCAL(ent); }) == m_DestructionQueue.end()); serializer.StringASCII("rng", SerializeRNG(m_RNG), 0, 32); serializer.NumberU32_Unbounded("next entity id", m_NextEntityId);