mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-10 22:31:40 +02:00
Fix crash on exporting maps for translation
This commit is contained in:
@@ -253,11 +253,18 @@ void ClientCommandManager::handleTranslateMapsCommand()
|
|||||||
|
|
||||||
logGlobal->info("Loading campaigns for export");
|
logGlobal->info("Loading campaigns for export");
|
||||||
for (auto const & campaignName : campaignList)
|
for (auto const & campaignName : campaignList)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
loadedCampaigns.push_back(CampaignHandler::getCampaign(campaignName.getName()));
|
loadedCampaigns.push_back(CampaignHandler::getCampaign(campaignName.getName()));
|
||||||
for (auto const & part : loadedCampaigns.back()->allScenarios())
|
for (auto const & part : loadedCampaigns.back()->allScenarios())
|
||||||
loadedCampaigns.back()->getMap(part, nullptr);
|
loadedCampaigns.back()->getMap(part, nullptr);
|
||||||
}
|
}
|
||||||
|
catch(std::exception & e)
|
||||||
|
{
|
||||||
|
logGlobal->warn("Campaign %s is invalid. Message: %s", campaignName.getName(), e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::map<std::string, std::map<std::string, std::string>> textsByMod;
|
std::map<std::string, std::map<std::string, std::string>> textsByMod;
|
||||||
VLC->generaltexth->exportAllTexts(textsByMod);
|
VLC->generaltexth->exportAllTexts(textsByMod);
|
||||||
|
@@ -136,6 +136,9 @@ si64 CCompressedStream::readMore(ui8 *data, si64 size)
|
|||||||
{
|
{
|
||||||
if (inflateState->avail_in == 0)
|
if (inflateState->avail_in == 0)
|
||||||
{
|
{
|
||||||
|
if (gzipStream == nullptr)
|
||||||
|
throw std::runtime_error("Potentially truncated gzip file");
|
||||||
|
|
||||||
//inflate ran out of available data or was not initialized yet
|
//inflate ran out of available data or was not initialized yet
|
||||||
// get new input data and update state accordingly
|
// get new input data and update state accordingly
|
||||||
si64 availSize = gzipStream->read(compressedBuffer.data(), compressedBuffer.size());
|
si64 availSize = gzipStream->read(compressedBuffer.data(), compressedBuffer.size());
|
||||||
|
@@ -208,6 +208,9 @@ void CMapLoaderH3M::readHeader()
|
|||||||
|
|
||||||
// optimization - load mappings only once to avoid slow parsing of map headers for map list
|
// optimization - load mappings only once to avoid slow parsing of map headers for map list
|
||||||
static const std::map<EMapFormat, MapIdentifiersH3M> identifierMappers = generateMappings();
|
static const std::map<EMapFormat, MapIdentifiersH3M> identifierMappers = generateMappings();
|
||||||
|
if (!identifierMappers.count(mapHeader->version))
|
||||||
|
throw std::runtime_error("Unsupported map format! Format ID " + std::to_string(static_cast<int>(mapHeader->version)));
|
||||||
|
|
||||||
const MapIdentifiersH3M & identifierMapper = identifierMappers.at(mapHeader->version);
|
const MapIdentifiersH3M & identifierMapper = identifierMappers.at(mapHeader->version);
|
||||||
|
|
||||||
reader->setIdentifierRemapper(identifierMapper);
|
reader->setIdentifierRemapper(identifierMapper);
|
||||||
|
@@ -1014,8 +1014,6 @@ void CMapLoaderJson::readTerrain()
|
|||||||
const JsonNode underground = getFromArchive(TERRAIN_FILE_NAMES[1]);
|
const JsonNode underground = getFromArchive(TERRAIN_FILE_NAMES[1]);
|
||||||
readTerrainLevel(underground, 1);
|
readTerrainLevel(underground, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
map->calculateWaterContent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CMapLoaderJson::MapObjectLoader::MapObjectLoader(CMapLoaderJson * _owner, JsonMap::value_type & json):
|
CMapLoaderJson::MapObjectLoader::MapObjectLoader(CMapLoaderJson * _owner, JsonMap::value_type & json):
|
||||||
|
@@ -410,9 +410,11 @@ bool MapReaderH3M::readBool()
|
|||||||
int8_t MapReaderH3M::readInt8Checked(int8_t lowerLimit, int8_t upperLimit)
|
int8_t MapReaderH3M::readInt8Checked(int8_t lowerLimit, int8_t upperLimit)
|
||||||
{
|
{
|
||||||
int8_t result = readInt8();
|
int8_t result = readInt8();
|
||||||
assert(result >= lowerLimit);
|
int8_t resultClamped = std::clamp(result, lowerLimit, upperLimit);
|
||||||
assert(result <= upperLimit);
|
if (result != resultClamped)
|
||||||
return std::clamp(result, lowerLimit, upperLimit);
|
logGlobal->warn("Map contains out of range value %d! Expected %d-%d", static_cast<int>(result), static_cast<int>(lowerLimit), static_cast<int>(upperLimit));
|
||||||
|
|
||||||
|
return resultClamped;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t MapReaderH3M::readUInt8()
|
uint8_t MapReaderH3M::readUInt8()
|
||||||
|
Reference in New Issue
Block a user