diff --git a/include/Engine/Common.h b/include/Engine/Common.h index ebdc90d0..7d6f520d 100644 --- a/include/Engine/Common.h +++ b/include/Engine/Common.h @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/include/Engine/Core/ComponentWrapper.h b/include/Engine/Core/ComponentWrapper.h index b1e5f9ad..f124d3d5 100644 --- a/include/Engine/Core/ComponentWrapper.h +++ b/include/Engine/Core/ComponentWrapper.h @@ -5,7 +5,7 @@ #include "Entity.h" #include "ComponentInfo.h" #include "Util/Any.h" -Minecraft hard drilling + struct ComponentWrapper { ComponentWrapper(const ComponentInfo& componentInfo, char* data) @@ -26,8 +26,13 @@ struct ComponentWrapper template T& Field(std::string name) { - unsigned int offset = Info.Fields.at(name).Offset; - return *reinterpret_cast(&Data[offset]); + const ComponentInfo::Field_t& field = Info.Fields.at(name); + if (sizeof(T) > field.Stride) { + std::stringstream message; + message << "Type size of \"" << typeid(T).name() << "\" doesn't match size of component field \"" << Info.Name << "." << name << "\"!"; + throw new std::runtime_error(message.str().c_str()); + } + return *reinterpret_cast(&Data[field.Offset]); } template