1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00

Workarounds for crashes from Google Play

- Do not crash on failure to read json from disk
- Add more debug information for crash on BattleHex access
This commit is contained in:
Ivan Savenko 2025-01-28 20:21:33 +00:00
parent 30f9ce5482
commit f4c3367e43
2 changed files with 14 additions and 6 deletions

View File

@ -25,6 +25,7 @@
#include "../../lib/CConfigHandler.h"
#include "../../lib/CThreadHelper.h"
#include "../../lib/ExceptionsCommon.h"
#include "../../lib/VCMIDirs.h"
#include "../../lib/constants/StringConstants.h"
#include "../../lib/entities/building/CBuilding.h"
@ -146,13 +147,20 @@ RenderHandler::AnimationLayoutMap & RenderHandler::getAnimationLayout(const Anim
for(auto & loader : configList)
{
auto stream = loader->load(jsonResource);
std::unique_ptr<ui8[]> textData(new ui8[stream->getSize()]);
stream->read(textData.get(), stream->getSize());
try {
auto stream = loader->load(jsonResource);
std::unique_ptr<ui8[]> textData(new ui8[stream->getSize()]);
stream->read(textData.get(), stream->getSize());
const JsonNode config(reinterpret_cast<const std::byte*>(textData.get()), stream->getSize(), path.getOriginalName());
const JsonNode config(reinterpret_cast<const std::byte*>(textData.get()), stream->getSize(), path.getOriginalName());
initFromJson(result, config, mode);
initFromJson(result, config, mode);
}
catch (const DataLoadingException & e)
{
// FIXME: sometimes triggered by generated animation assets, e.g. lava/water tiles
logGlobal->error("Failed to load animation file! Reason: %s", e.what());
}
}
animationLayouts[actualPath] = result;

View File

@ -118,7 +118,7 @@ public:
if(hasToBeValid)
{
if(x < 0 || x >= GameConstants::BFIELD_WIDTH || y < 0 || y >= GameConstants::BFIELD_HEIGHT)
throw std::runtime_error("Valid hex required");
throw std::runtime_error("Hex at (" + std::to_string(x) + ", " + std::to_string(y) + ") is not valid!");
}
hex = x + y * GameConstants::BFIELD_WIDTH;