From 986db9cfc5a1c9015503b5366c65a377f8c8a259 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sun, 2 Jun 2024 14:02:16 +1000 Subject: [PATCH] further MaterialDatabase checks --- source/game/StarMaterialDatabase.hpp | 18 ++++++++++++------ source/game/StarTileDrawer.cpp | 1 - source/rendering/StarTilePainter.cpp | 1 - 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/source/game/StarMaterialDatabase.hpp b/source/game/StarMaterialDatabase.hpp index b890e30..f20a3e2 100644 --- a/source/game/StarMaterialDatabase.hpp +++ b/source/game/StarMaterialDatabase.hpp @@ -188,15 +188,21 @@ private: }; inline MaterialRenderProfileConstPtr MaterialDatabase::materialRenderProfile(MaterialId materialId) const { - if (materialId >= m_materials.size()) - return {}; - return m_materials[materialId]->materialRenderProfile; + if (materialId < m_materials.size()) { + if (auto const& mat = m_materials[materialId]) + return mat->materialRenderProfile; + } + + return {}; } inline MaterialRenderProfileConstPtr MaterialDatabase::modRenderProfile(ModId modId) const { - if (modId >= m_mods.size()) - return {}; - return m_mods[modId]->modRenderProfile; + if (modId < m_mods.size()) { + if (auto const& mod = m_mods[modId]) + return mod->modRenderProfile; + } + + return {}; } inline bool MaterialDatabase::foregroundLightTransparent(MaterialId materialId) const { diff --git a/source/game/StarTileDrawer.cpp b/source/game/StarTileDrawer.cpp index 3ac8e48..70cd7d0 100644 --- a/source/game/StarTileDrawer.cpp +++ b/source/game/StarTileDrawer.cpp @@ -106,7 +106,6 @@ bool TileDrawer::produceTerrainDrawables(Drawables& drawables, }; auto materialRenderProfile = materialDatabase->materialRenderProfile(material); - auto modRenderProfile = materialDatabase->modRenderProfile(mod); if (materialRenderProfile) { diff --git a/source/rendering/StarTilePainter.cpp b/source/rendering/StarTilePainter.cpp index 58d9d28..f9cff34 100644 --- a/source/rendering/StarTilePainter.cpp +++ b/source/rendering/StarTilePainter.cpp @@ -277,7 +277,6 @@ bool TilePainter::produceTerrainPrimitives(HashMapmaterialRenderProfile(material); - auto modRenderProfile = materialDatabase->modRenderProfile(mod); if (materialRenderProfile) {