summaryrefslogtreecommitdiff
path: root/src/gui/models/shopitems.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-10 22:23:45 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-10 22:23:45 +0300
commitfca0f15e161755e0a430802b1b38bdda0cb033cb (patch)
treec81055dd71fa7a6510d029da65d7f0a36078a99a /src/gui/models/shopitems.cpp
parenteaf9448af11e82a567a82aafba95f65e984d9942 (diff)
downloadmv-fca0f15e161755e0a430802b1b38bdda0cb033cb.tar.gz
mv-fca0f15e161755e0a430802b1b38bdda0cb033cb.tar.bz2
mv-fca0f15e161755e0a430802b1b38bdda0cb033cb.tar.xz
mv-fca0f15e161755e0a430802b1b38bdda0cb033cb.zip
Fix crash on closing sell dialog in some cases.
Diffstat (limited to 'src/gui/models/shopitems.cpp')
-rw-r--r--src/gui/models/shopitems.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/gui/models/shopitems.cpp b/src/gui/models/shopitems.cpp
index 2fd399cb0..3a0d933cc 100644
--- a/src/gui/models/shopitems.cpp
+++ b/src/gui/models/shopitems.cpp
@@ -111,11 +111,27 @@ ShopItem *ShopItems::at(unsigned int i) const
return mShopItems.at(i);
}
+bool ShopItems::findInAllItems(std::vector<ShopItem*>::iterator &it,
+ const ShopItem *const item)
+{
+ const std::vector<ShopItem*>::iterator it_end = mAllShopItems.end();
+ for (it = mAllShopItems.begin(); it != it_end; ++ it)
+ {
+ if (*it == item)
+ return true;
+ }
+ return false;
+}
+
void ShopItems::erase(const unsigned int i)
{
if (i >= static_cast<unsigned int>(mShopItems.size()))
return;
+ ShopItem *item = *(mShopItems.begin() + i);
+ std::vector<ShopItem*>::iterator it;
+ if (findInAllItems(it, item))
+ mAllShopItems.erase(it);
mShopItems.erase(mShopItems.begin() + i);
}
@@ -125,6 +141,9 @@ void ShopItems::del(const unsigned int i)
return;
ShopItem *item = *(mShopItems.begin() + i);
+ std::vector<ShopItem*>::iterator it;
+ if (findInAllItems(it, item))
+ mAllShopItems.erase(it);
mShopItems.erase(mShopItems.begin() + i);
delete item;
}