diff --git a/client/widgets/CArtifactHolder.cpp b/client/widgets/CArtifactHolder.cpp index 0af6f901a..2c6be9976 100644 --- a/client/widgets/CArtifactHolder.cpp +++ b/client/widgets/CArtifactHolder.cpp @@ -595,7 +595,7 @@ CArtifactsOfHero::CArtifactsOfHero(std::map ArtWo { if(createCommonPart) { - commonInfo = new CArtifactsOfHero::SCommonPart; + commonInfo = std::make_shared(); commonInfo->participants.insert(this); } @@ -622,7 +622,7 @@ CArtifactsOfHero::CArtifactsOfHero(const Point& position, bool createCommonPart { if(createCommonPart) { - commonInfo = new CArtifactsOfHero::SCommonPart; + commonInfo = std::make_shared(); commonInfo->participants.insert(this); } diff --git a/client/widgets/CArtifactHolder.h b/client/widgets/CArtifactHolder.h index 40b308c47..b13ca0936 100644 --- a/client/widgets/CArtifactHolder.h +++ b/client/widgets/CArtifactHolder.h @@ -107,7 +107,8 @@ public: std::set participants; // Needed to mark slots. void reset(); - } * commonInfo; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally + }; + std::shared_ptr commonInfo; //when we have more than one CArtifactsOfHero in one window with exchange possibility, we use this (eg. in exchange window); to be provided externally bool updateState; // Whether the commonInfo should be updated on setHero or not. diff --git a/client/widgets/CGarrisonInt.cpp b/client/widgets/CGarrisonInt.cpp index 97d584910..21fbe18d3 100644 --- a/client/widgets/CGarrisonInt.cpp +++ b/client/widgets/CGarrisonInt.cpp @@ -169,7 +169,7 @@ bool CGarrisonSlot::highlightOrDropArtifact() bool artSelected = false; if (CWindowWithArtifacts* chw = dynamic_cast(GH.topInt())) //dirty solution { - const CArtifactsOfHero::SCommonPart *commonInfo = chw->artSets.front()->commonInfo; + const std::shared_ptr commonInfo = chw->artSets.front()->commonInfo; if (const CArtifactInstance *art = commonInfo->src.art) { const CGHeroInstance *srcHero = commonInfo->src.AOH->getHero(); diff --git a/client/windows/CHeroWindow.cpp b/client/windows/CHeroWindow.cpp index 0975daefd..ece7bd7f0 100644 --- a/client/windows/CHeroWindow.cpp +++ b/client/windows/CHeroWindow.cpp @@ -47,7 +47,7 @@ const TBonusListPtr CHeroWithMaybePickedArtifact::getAllBonuses(const CSelector TBonusListPtr heroBonuses = hero->getAllBonuses(selector, limit, hero); TBonusListPtr bonusesFromPickedUpArtifact; - CArtifactsOfHero::SCommonPart *cp = cww->artSets.size() ? cww->artSets.front()->commonInfo : nullptr; + std::shared_ptr cp = cww->artSets.size() ? cww->artSets.front()->commonInfo : nullptr; if(cp && cp->src.art && cp->src.valid() && cp->src.AOH && cp->src.AOH->getHero() == hero) { bonusesFromPickedUpArtifact = cp->src.art->getAllBonuses(selector, limit, hero); @@ -317,7 +317,7 @@ void CHeroWindow::commanderWindow() { //TODO: allow equipping commander artifacts by drag / drop //bool artSelected = false; - const CArtifactsOfHero::SCommonPart *commonInfo = artSets.front()->commonInfo; + const std::shared_ptr commonInfo = artSets.front()->commonInfo; if (const CArtifactInstance *art = commonInfo->src.art) { diff --git a/client/windows/CTradeWindow.cpp b/client/windows/CTradeWindow.cpp index 485a52d73..b3b52e680 100644 --- a/client/windows/CTradeWindow.cpp +++ b/client/windows/CTradeWindow.cpp @@ -390,7 +390,7 @@ void CTradeWindow::initItems(bool Left) BLOCK_CAPTURING; arts = new CArtifactsOfHero(Point(pos.x+xOffset, pos.y+yOffset)); - arts->commonInfo = new CArtifactsOfHero::SCommonPart; + arts->commonInfo = std::make_shared(); arts->commonInfo->participants.insert(arts); arts->recActions = 255; arts->setHero(hero); diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index fecff8783..448728f7b 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -908,7 +908,7 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, prepareBackground(); artifs[0] = new CArtifactsOfHero(Point(-334, 150)); - artifs[0]->commonInfo = new CArtifactsOfHero::SCommonPart; + artifs[0]->commonInfo = std::make_shared(); artifs[0]->commonInfo->participants.insert(artifs[0]); artifs[0]->setHero(heroInst[0]); artifs[1] = new CArtifactsOfHero(Point(96, 150)); @@ -1004,7 +1004,6 @@ CExchangeWindow::CExchangeWindow(ObjectInstanceID hero1, ObjectInstanceID hero2, CExchangeWindow::~CExchangeWindow() //d-tor { - delete artifs[0]->commonInfo; artifs[0]->commonInfo = nullptr; artifs[1]->commonInfo = nullptr; }