From 5f8496ca103fabb4cfc265d8d936e194129a17ef Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 30 Jan 2017 19:10:14 +0300 Subject: Clean buy dialog dungling pointer if buy dialog was destroyed. --- src/gui/windows/buydialog.cpp | 1 + src/net/buysellhandler.h | 5 +++++ src/net/ea/buysellhandler.cpp | 6 ++++++ src/net/ea/buysellhandler.h | 3 +++ 4 files changed, 15 insertions(+) diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp index b0e7aaa04..ebf4ef8a4 100644 --- a/src/gui/windows/buydialog.cpp +++ b/src/gui/windows/buydialog.cpp @@ -409,6 +409,7 @@ BuyDialog::~BuyDialog() { delete2(mShopItems); instances.remove(this); + buySellHandler->cleanDialogReference(this); } void BuyDialog::setMoney(const int amount) diff --git a/src/net/buysellhandler.h b/src/net/buysellhandler.h index 79cb60b6c..e6f66129c 100644 --- a/src/net/buysellhandler.h +++ b/src/net/buysellhandler.h @@ -25,6 +25,8 @@ #include "resources/item/shopitem.h" +class BuyDialog; + namespace Net { @@ -52,6 +54,9 @@ class BuySellHandler notfinal const int amount) const = 0; virtual void close() const = 0; + + virtual void cleanDialogReference(const BuyDialog *const dialog) + const = 0; }; } // namespace Net diff --git a/src/net/ea/buysellhandler.cpp b/src/net/ea/buysellhandler.cpp index 9a147347a..21769cef4 100644 --- a/src/net/ea/buysellhandler.cpp +++ b/src/net/ea/buysellhandler.cpp @@ -35,4 +35,10 @@ BuySellHandler::BuySellHandler() BuySellRecv::mBuyDialog = nullptr; } +void BuySellHandler::cleanDialogReference(const BuyDialog *const dialog) const +{ + if (BuySellRecv::mBuyDialog == dialog) + BuySellRecv::mBuyDialog = nullptr; +} + } // namespace Ea diff --git a/src/net/ea/buysellhandler.h b/src/net/ea/buysellhandler.h index 4343cd256..2c5e1caad 100644 --- a/src/net/ea/buysellhandler.h +++ b/src/net/ea/buysellhandler.h @@ -34,6 +34,9 @@ class BuySellHandler notfinal : public Net::BuySellHandler BuySellHandler(); A_DELETE_COPY(BuySellHandler) + + void cleanDialogReference(const BuyDialog *const dialog) const + override final; }; } // namespace Ea -- cgit v1.2.3-60-g2f50