mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-25 12:14:46 +02:00
vcmi: fix road and river loading
It actually catched by MapFormat.Terrain test crash. So, this is a fix (functions does not trowing exceptons, it returns NULL if something is wrong).
This commit is contained in:
parent
7ef5163d9d
commit
c84a9f32f6
@ -1005,26 +1005,19 @@ void CMapLoaderJson::readTerrainTile(const std::string & src, TerrainTile & tile
|
|||||||
if (startPos >= src.size())
|
if (startPos >= src.size())
|
||||||
return;
|
return;
|
||||||
bool hasRoad = true;
|
bool hasRoad = true;
|
||||||
//FIXME: check without exceptions?
|
|
||||||
{//road type
|
{//road type
|
||||||
const std::string typeCode = src.substr(startPos, 2);
|
const std::string typeCode = src.substr(startPos, 2);
|
||||||
startPos += 2;
|
startPos += 2;
|
||||||
try
|
tile.roadType = getRoadByCode(typeCode);
|
||||||
|
if(!tile.roadType) //it's not a road, it's a river
|
||||||
{
|
{
|
||||||
tile.roadType = getRoadByCode(typeCode);
|
tile.roadType = VLC->roadTypeHandler->getById(Road::NO_ROAD);
|
||||||
}
|
tile.riverType = getRiverByCode(typeCode);
|
||||||
catch (const std::exception&) //it's not a road, it's a river
|
hasRoad = false;
|
||||||
{
|
if(!tile.riverType)
|
||||||
try
|
|
||||||
{
|
|
||||||
tile.riverType = getRiverByCode(typeCode);
|
|
||||||
hasRoad = false;
|
|
||||||
}
|
|
||||||
catch (const std::exception&)
|
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid river type in " + src);
|
throw std::runtime_error("Invalid river type in " + src);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasRoad)
|
if (hasRoad)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user