diff --git a/src/object_base.h b/src/object_base.h index 446279f934..b60f7cb626 100644 --- a/src/object_base.h +++ b/src/object_base.h @@ -43,6 +43,7 @@ struct Object : ObjectPool::PoolItem<&_object_pool> { static inline void IncTypeCount(ObjectType type) { dbg_assert(type < NUM_OBJECTS); + if (type >= counts.size()) counts.resize(type + 1); counts[type]++; } @@ -54,6 +55,7 @@ struct Object : ObjectPool::PoolItem<&_object_pool> { static inline void DecTypeCount(ObjectType type) { dbg_assert(type < NUM_OBJECTS); + dbg_assert(type < counts.size()); counts[type]--; } @@ -65,17 +67,18 @@ struct Object : ObjectPool::PoolItem<&_object_pool> { static inline uint16 GetTypeCount(ObjectType type) { dbg_assert(type < NUM_OBJECTS); + if (type >= counts.size()) return 0; return counts[type]; } /** Resets object counts. */ static inline void ResetTypeCounts() { - memset(&counts, 0, sizeof(counts)); + counts.clear(); } protected: - static uint16 counts[NUM_OBJECTS]; ///< Number of objects per type ingame + static std::vector counts; ///< Number of objects per type ingame }; /** diff --git a/src/object_cmd.cpp b/src/object_cmd.cpp index 430e4bde00..f994a6098e 100644 --- a/src/object_cmd.cpp +++ b/src/object_cmd.cpp @@ -41,7 +41,7 @@ ObjectPool _object_pool("Object"); INSTANTIATE_POOL_METHODS(Object) -uint16 Object::counts[NUM_OBJECTS]; +std::vector Object::counts; /** * Get the object associated with a tile.