From 8bd5a428b902d1800a73595c351e142ebb62413c Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 15 Jan 2016 20:25:48 +0100 Subject: [PATCH] EntityFileParser now ignores component fields not present in component definition instead of crashing. --- src/Engine/Core/EntityFileParser.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Engine/Core/EntityFileParser.cpp b/src/Engine/Core/EntityFileParser.cpp index 9f338d71..1633bbc7 100644 --- a/src/Engine/Core/EntityFileParser.cpp +++ b/src/Engine/Core/EntityFileParser.cpp @@ -42,7 +42,12 @@ void EntityFileParser::onStartComponentField(EntityID entity, const std::string& { EntityID realEntity = m_EntityIDMapper.at(entity); ComponentWrapper component = m_World->GetComponent(realEntity, componentType); - auto& field = component.Info.Fields.at(fieldName); + auto fieldIt = component.Info.Fields.find(fieldName); + if (fieldIt == component.Info.Fields.end()) { + LOG_ERROR("Tried to set unknown field \"%s\" of component type \"%s\"! Ignoring.", fieldName.c_str(), componentType.c_str()); + return; + } + auto& field = fieldIt->second; LOG_DEBUG("Field \"%s\" type \"%s\"", fieldName.c_str(), field.Type.c_str()); LOG_DEBUG("Attributes:"); @@ -58,7 +63,11 @@ void EntityFileParser::onFieldData(EntityID entity, const std::string& component { EntityID realEntity = m_EntityIDMapper.at(entity); ComponentWrapper component = m_World->GetComponent(realEntity, componentType); - auto& field = component.Info.Fields.at(fieldName); + auto fieldIt = component.Info.Fields.find(fieldName); + if (fieldIt == component.Info.Fields.end()) { + return; + } + auto& field = fieldIt->second; char* data = component.Data + field.Offset; EntityFile::WriteValueData(data, field, fieldData);