From 201681e4ca5e4580022852a5729f1ca65f3810ae Mon Sep 17 00:00:00 2001 From: Mergul Date: Thu, 4 Apr 2019 17:54:39 +0200 Subject: [PATCH] -fixed small issue, now Template.getComponent should return null if component doesn't exist in template --- source/ecs/entity.d | 2 +- source/ecs/manager.d | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/ecs/entity.d b/source/ecs/entity.d index 931dfa0..09a5996 100644 --- a/source/ecs/entity.d +++ b/source/ecs/entity.d @@ -65,7 +65,7 @@ export struct EntityTemplate */ T* getComponent(T)() nothrow @nogc { - if(T.component_id >= info.tmpl_deltas.length)return null; + if(T.component_id >= info.tmpl_deltas.length || info.tmpl_deltas[T.component_id] == ushort.max)return null; return cast(T*)(entity_data.ptr + info.tmpl_deltas[T.component_id]); } } diff --git a/source/ecs/manager.d b/source/ecs/manager.d index 0e45551..ddcbba5 100644 --- a/source/ecs/manager.d +++ b/source/ecs/manager.d @@ -1171,7 +1171,7 @@ class EntityManager info.size = EntityID.sizeof; info.alignment = EntityID.alignof; - info.tmpl_deltas = Mallocator.instance.makeArray!ushort(ids[$ - 1] + 1); + info.tmpl_deltas = Mallocator.instance.makeArray!ushort(ids[$ - 1] + 1,ushort.max); uint components_size = EntityID.sizeof; foreach (i, id; ids)