Browse Source

Add fallback for empty terrain types. Still it's a workaround and does not solve the root cause.

Tomasz Zieliński 2 years ago
parent
commit
23a5a32756
1 changed files with 10 additions and 1 deletions
  1. 10 1
      lib/rmg/Functions.cpp

+ 10 - 1
lib/rmg/Functions.cpp

@@ -134,7 +134,16 @@ void initTerrainType(Zone & zone, CMapGenerator & gen)
 		}
 		}
 		else
 		else
 		{
 		{
-			zone.setTerrainType(*RandomGeneratorUtil::nextItem(zone.getTerrainTypes(), gen.rand));
+			auto terrainTypes = zone.getTerrainTypes();
+			if (terrainTypes.empty())
+			{
+				logGlobal->warn("No terrain types found, falling back to DIRT");
+				zone.setTerrainType(ETerrainId::DIRT);
+			}
+			else
+			{
+				zone.setTerrainType(*RandomGeneratorUtil::nextItem(terrainTypes, gen.rand));
+			}
 		}
 		}
 		
 		
 		//Now, replace disallowed terrains on surface and in the underground
 		//Now, replace disallowed terrains on surface and in the underground