1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Fixed memory corruption on usage of radial wheel to reorder towns/heroes

This commit is contained in:
Ivan Savenko 2023-12-16 12:49:05 +02:00
parent aadfde27bc
commit 5f4608c9f0
2 changed files with 8 additions and 16 deletions

View File

@ -218,8 +218,7 @@ CHeroList::CEmptyHeroItem::CEmptyHeroItem()
CHeroList::CHeroItem::CHeroItem(CHeroList *parent, const CGHeroInstance * Hero) CHeroList::CHeroItem::CHeroItem(CHeroList *parent, const CGHeroInstance * Hero)
: CListItem(parent), : CListItem(parent),
hero(Hero), hero(Hero)
parentList(parent)
{ {
OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
movement = std::make_shared<CAnimImage>(AnimationPath::builtin("IMOBIL"), 0, 0, 0, 1); movement = std::make_shared<CAnimImage>(AnimationPath::builtin("IMOBIL"), 0, 0, 0, 1);
@ -285,19 +284,17 @@ void CHeroList::CHeroItem::gesture(bool on, const Point & initialPosition, const
const CGHeroInstance * heroLower = (heroPos > heroes.size() - 2) ? nullptr : heroes[heroPos + 1]; const CGHeroInstance * heroLower = (heroPos > heroes.size() - 2) ? nullptr : heroes[heroPos + 1];
std::vector<RadialMenuConfig> menuElements = { std::vector<RadialMenuConfig> menuElements = {
{ RadialMenuConfig::ITEM_ALT_NN, heroUpper != nullptr, "altUpTop", "vcmi.radialWheel.moveTop", [this, heroPos]() { RadialMenuConfig::ITEM_ALT_NN, heroUpper != nullptr, "altUpTop", "vcmi.radialWheel.moveTop", [heroPos]()
{ {
for (int i = heroPos; i > 0; i--) for (int i = heroPos; i > 0; i--)
LOCPLINT->localState->swapWanderingHero(i, i - 1); LOCPLINT->localState->swapWanderingHero(i, i - 1);
parentList->updateWidget();
} }, } },
{ RadialMenuConfig::ITEM_ALT_NW, heroUpper != nullptr, "altUp", "vcmi.radialWheel.moveUp", [this, heroPos](){LOCPLINT->localState->swapWanderingHero(heroPos, heroPos - 1); parentList->updateWidget(); } }, { RadialMenuConfig::ITEM_ALT_NW, heroUpper != nullptr, "altUp", "vcmi.radialWheel.moveUp", [heroPos](){LOCPLINT->localState->swapWanderingHero(heroPos, heroPos - 1); } },
{ RadialMenuConfig::ITEM_ALT_SW, heroLower != nullptr, "altDown", "vcmi.radialWheel.moveDown", [this, heroPos](){ LOCPLINT->localState->swapWanderingHero(heroPos, heroPos + 1); parentList->updateWidget(); } }, { RadialMenuConfig::ITEM_ALT_SW, heroLower != nullptr, "altDown", "vcmi.radialWheel.moveDown", [heroPos](){ LOCPLINT->localState->swapWanderingHero(heroPos, heroPos + 1); } },
{ RadialMenuConfig::ITEM_ALT_SS, heroLower != nullptr, "altDownBottom", "vcmi.radialWheel.moveBottom", [this, heroPos, heroes]() { RadialMenuConfig::ITEM_ALT_SS, heroLower != nullptr, "altDownBottom", "vcmi.radialWheel.moveBottom", [heroPos, heroes]()
{ {
for (int i = heroPos; i < heroes.size() - 1; i++) for (int i = heroPos; i < heroes.size() - 1; i++)
LOCPLINT->localState->swapWanderingHero(i, i + 1); LOCPLINT->localState->swapWanderingHero(i, i + 1);
parentList->updateWidget();
} }, } },
}; };
@ -365,8 +362,7 @@ std::shared_ptr<CIntObject> CTownList::createItem(size_t index)
} }
CTownList::CTownItem::CTownItem(CTownList *parent, const CGTownInstance *Town): CTownList::CTownItem::CTownItem(CTownList *parent, const CGTownInstance *Town):
CListItem(parent), CListItem(parent)
parentList(parent)
{ {
const std::vector<const CGTownInstance *> towns = LOCPLINT->localState->getOwnedTowns(); const std::vector<const CGTownInstance *> towns = LOCPLINT->localState->getOwnedTowns();
townIndex = std::distance(towns.begin(), std::find(towns.begin(), towns.end(), Town)); townIndex = std::distance(towns.begin(), std::find(towns.begin(), towns.end(), Town));
@ -430,15 +426,13 @@ void CTownList::CTownItem::gesture(bool on, const Point & initialPosition, const
{ {
for (int i = townIndex; i > 0; i--) for (int i = townIndex; i > 0; i--)
LOCPLINT->localState->swapOwnedTowns(i, i - 1); LOCPLINT->localState->swapOwnedTowns(i, i - 1);
parentList->updateWidget();
} }, } },
{ RadialMenuConfig::ITEM_ALT_NW, townUpperPos > -1, "altUp", "vcmi.radialWheel.moveUp", [this, townUpperPos](){LOCPLINT->localState->swapOwnedTowns(townIndex, townUpperPos); parentList->updateWidget(); } }, { RadialMenuConfig::ITEM_ALT_NW, townUpperPos > -1, "altUp", "vcmi.radialWheel.moveUp", [this, townUpperPos](){LOCPLINT->localState->swapOwnedTowns(townIndex, townUpperPos); } },
{ RadialMenuConfig::ITEM_ALT_SW, townLowerPos > -1, "altDown", "vcmi.radialWheel.moveDown", [this, townLowerPos](){ LOCPLINT->localState->swapOwnedTowns(townIndex, townLowerPos); parentList->updateWidget(); } }, { RadialMenuConfig::ITEM_ALT_SW, townLowerPos > -1, "altDown", "vcmi.radialWheel.moveDown", [this, townLowerPos](){ LOCPLINT->localState->swapOwnedTowns(townIndex, townLowerPos); } },
{ RadialMenuConfig::ITEM_ALT_SS, townLowerPos > -1, "altDownBottom", "vcmi.radialWheel.moveBottom", [this, towns]() { RadialMenuConfig::ITEM_ALT_SS, townLowerPos > -1, "altDownBottom", "vcmi.radialWheel.moveBottom", [this, towns]()
{ {
for (int i = townIndex; i < towns.size() - 1; i++) for (int i = townIndex; i < towns.size() - 1; i++)
LOCPLINT->localState->swapOwnedTowns(i, i + 1); LOCPLINT->localState->swapOwnedTowns(i, i + 1);
parentList->updateWidget();
} }, } },
}; };

View File

@ -117,7 +117,6 @@ class CHeroList : public CList
std::shared_ptr<CAnimImage> movement; std::shared_ptr<CAnimImage> movement;
std::shared_ptr<CAnimImage> mana; std::shared_ptr<CAnimImage> mana;
std::shared_ptr<CAnimImage> portrait; std::shared_ptr<CAnimImage> portrait;
CHeroList *parentList;
public: public:
const CGHeroInstance * const hero; const CGHeroInstance * const hero;
@ -152,7 +151,6 @@ class CTownList : public CList
class CTownItem : public CListItem class CTownItem : public CListItem
{ {
std::shared_ptr<CAnimImage> picture; std::shared_ptr<CAnimImage> picture;
CTownList *parentList;
public: public:
int townIndex; int townIndex;