Prechádzať zdrojové kódy

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
Ivan Savenko 8 mesiacov pred
rodič
commit
f4c3367e43
2 zmenil súbory, kde vykonal 14 pridanie a 6 odobranie
  1. 13 5
      client/renderSDL/RenderHandler.cpp
  2. 1 1
      lib/battle/BattleHex.h

+ 13 - 5
client/renderSDL/RenderHandler.cpp

@@ -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;

+ 1 - 1
lib/battle/BattleHex.h

@@ -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;