From 496bca1a5919b479d590c81d187f56d86861a0a0 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 17 Dec 2023 20:05:34 +0200 Subject: [PATCH] Attempt to track down mystery crash on Android --- .../AObjectTypeHandler.cpp | 22 ++++++++++++++++--- .../AObjectTypeHandler.h | 5 +++-- .../CObjectClassesHandler.cpp | 1 - 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/mapObjectConstructors/AObjectTypeHandler.cpp b/lib/mapObjectConstructors/AObjectTypeHandler.cpp index 1d915d5f8..17b31a5ef 100644 --- a/lib/mapObjectConstructors/AObjectTypeHandler.cpp +++ b/lib/mapObjectConstructors/AObjectTypeHandler.cpp @@ -20,6 +20,19 @@ VCMI_LIB_NAMESPACE_BEGIN +AObjectTypeHandler::AObjectTypeHandler() = default; + +AObjectTypeHandler::~AObjectTypeHandler() +{ + // FIXME: currently on Android there is a weird crash in destructor of 'base' member + // this code attempts to localize and fix this crash + if (base) + { + base->clear(); + base.reset(); + } +} + std::string AObjectTypeHandler::getJsonKey() const { return modScope + ':' + subTypeName; @@ -55,7 +68,8 @@ static ui32 loadJsonOrMax(const JsonNode & input) void AObjectTypeHandler::init(const JsonNode & input) { - base = input["base"]; + if (!input["base"].isNull()) + base = std::make_unique(input["base"]); if (!input["rmg"].isNull()) { @@ -72,7 +86,8 @@ void AObjectTypeHandler::init(const JsonNode & input) for (auto entry : input["templates"].Struct()) { entry.second.setType(JsonNode::JsonType::DATA_STRUCT); - JsonUtils::inherit(entry.second, base); + if (base) + JsonUtils::inherit(entry.second, *base); auto * tmpl = new ObjectTemplate; tmpl->id = Obj(type); @@ -171,7 +186,8 @@ void AObjectTypeHandler::addTemplate(const std::shared_ptr void AObjectTypeHandler::addTemplate(JsonNode config) { config.setType(JsonNode::JsonType::DATA_STRUCT); // ensure that input is not null - JsonUtils::inherit(config, base); + if (base) + JsonUtils::inherit(config, *base); auto * tmpl = new ObjectTemplate; tmpl->id = Obj(type); tmpl->subid = subtype; diff --git a/lib/mapObjectConstructors/AObjectTypeHandler.h b/lib/mapObjectConstructors/AObjectTypeHandler.h index 04e7c2ca5..b2443bfc9 100644 --- a/lib/mapObjectConstructors/AObjectTypeHandler.h +++ b/lib/mapObjectConstructors/AObjectTypeHandler.h @@ -27,7 +27,7 @@ class DLL_LINKAGE AObjectTypeHandler : public boost::noncopyable RandomMapInfo rmgInfo; - JsonNode base; /// describes base template + std::unique_ptr base; /// describes base template std::vector> templates; @@ -54,7 +54,8 @@ protected: virtual void initTypeData(const JsonNode & input); public: - virtual ~AObjectTypeHandler() = default; + AObjectTypeHandler(); + virtual ~AObjectTypeHandler(); si32 getIndex() const; si32 getSubIndex() const; diff --git a/lib/mapObjectConstructors/CObjectClassesHandler.cpp b/lib/mapObjectConstructors/CObjectClassesHandler.cpp index 11c79e733..ac89ef465 100644 --- a/lib/mapObjectConstructors/CObjectClassesHandler.cpp +++ b/lib/mapObjectConstructors/CObjectClassesHandler.cpp @@ -443,7 +443,6 @@ void CObjectClassesHandler::generateExtraMonolithsForRMG(ObjectClass * container //deep copy of noncopyable object :? auto newPortal = std::make_shared>(); newPortal->rmgInfo = portal->getRMGInfo(); - newPortal->base = portal->base; //not needed? newPortal->templates = portal->getTemplates(); newPortal->sounds = portal->getSounds(); newPortal->aiValue = portal->getAiValue();