summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-03-28 00:39:12 +0300
committerAndrei Karas <akaras@inbox.ru>2014-03-28 11:04:23 +0300
commit0c35dab0ba366f85b40ef1795125521f1df8c264 (patch)
treedde6abde3288f543ae96a2468b2275af8a03e704
parent47cc515695fcd0b16467506e4984d2ec38fad4e4 (diff)
downloadplus-0c35dab0ba366f85b40ef1795125521f1df8c264.tar.gz
plus-0c35dab0ba366f85b40ef1795125521f1df8c264.tar.bz2
plus-0c35dab0ba366f85b40ef1795125521f1df8c264.tar.xz
plus-0c35dab0ba366f85b40ef1795125521f1df8c264.zip
simplify variables cleanup.
-rw-r--r--src/actormanager.cpp2
-rw-r--r--src/animatedsprite.cpp5
-rw-r--r--src/being/actorsprite.cpp6
-rw-r--r--src/being/being.cpp58
-rw-r--r--src/being/compoundsprite.cpp10
-rw-r--r--src/being/localplayer.cpp7
-rw-r--r--src/being/playerinfo.cpp8
-rw-r--r--src/beingequipbackend.cpp12
-rw-r--r--src/client.cpp79
-rw-r--r--src/commands.cpp4
-rw-r--r--src/configuration.cpp4
-rw-r--r--src/depricatedevent.cpp5
-rw-r--r--src/game.cpp85
-rw-r--r--src/gui/font.cpp4
-rw-r--r--src/gui/gui.cpp31
-rw-r--r--src/gui/theme.cpp7
-rw-r--r--src/gui/viewport.cpp12
-rw-r--r--src/gui/widgets/button.cpp6
-rw-r--r--src/gui/widgets/characterdisplay.cpp4
-rw-r--r--src/gui/widgets/dropshortcutcontainer.cpp6
-rw-r--r--src/gui/widgets/emotepage.cpp5
-rw-r--r--src/gui/widgets/guitable.cpp8
-rw-r--r--src/gui/widgets/itemcontainer.cpp7
-rw-r--r--src/gui/widgets/itemlinkhandler.cpp5
-rw-r--r--src/gui/widgets/itemshortcutcontainer.cpp8
-rw-r--r--src/gui/widgets/layout.cpp7
-rw-r--r--src/gui/widgets/popup.cpp5
-rw-r--r--src/gui/widgets/progressbar.cpp5
-rw-r--r--src/gui/widgets/progressindicator.cpp5
-rw-r--r--src/gui/widgets/scrollarea.cpp8
-rw-r--r--src/gui/widgets/shortcutcontainer.cpp5
-rw-r--r--src/gui/widgets/slider.cpp5
-rw-r--r--src/gui/widgets/spellshortcutcontainer.cpp5
-rw-r--r--src/gui/widgets/tabbedarea.cpp19
-rw-r--r--src/gui/widgets/tabs/chattab.cpp7
-rw-r--r--src/gui/widgets/tabs/setup_audio.cpp8
-rw-r--r--src/gui/widgets/tabs/setup_colors.cpp11
-rw-r--r--src/gui/widgets/tabs/setup_input.cpp21
-rw-r--r--src/gui/widgets/tabs/setup_joystick.cpp4
-rw-r--r--src/gui/widgets/tabs/setup_other.cpp10
-rw-r--r--src/gui/widgets/tabs/setup_perfomance.cpp4
-rw-r--r--src/gui/widgets/tabs/setup_relations.cpp14
-rw-r--r--src/gui/widgets/tabs/setup_theme.cpp28
-rw-r--r--src/gui/widgets/tabs/setup_touch.cpp10
-rw-r--r--src/gui/widgets/tabs/setup_video.cpp13
-rw-r--r--src/gui/widgets/tabs/setup_visual.cpp19
-rw-r--r--src/gui/widgets/tabs/setuptabscroll.cpp7
-rw-r--r--src/gui/widgets/tabs/tab.cpp8
-rw-r--r--src/gui/widgets/textfield.cpp4
-rw-r--r--src/gui/widgets/window.cpp11
-rw-r--r--src/gui/windowmenu.cpp4
-rw-r--r--src/gui/windows/buydialog.cpp5
-rw-r--r--src/gui/windows/changeemaildialog.cpp4
-rw-r--r--src/gui/windows/changepassworddialog.cpp4
-rw-r--r--src/gui/windows/charcreatedialog.cpp13
-rw-r--r--src/gui/windows/chatwindow.cpp13
-rw-r--r--src/gui/windows/debugwindow.cpp10
-rw-r--r--src/gui/windows/emotewindow.cpp22
-rw-r--r--src/gui/windows/equipmentwindow.cpp10
-rw-r--r--src/gui/windows/inventorywindow.cpp5
-rw-r--r--src/gui/windows/itemamountwindow.cpp4
-rw-r--r--src/gui/windows/logindialog.cpp7
-rw-r--r--src/gui/windows/minimap.cpp4
-rw-r--r--src/gui/windows/ministatuswindow.cpp7
-rw-r--r--src/gui/windows/npcdialog.cpp59
-rw-r--r--src/gui/windows/questswindow.cpp7
-rw-r--r--src/gui/windows/quitdialog.cpp13
-rw-r--r--src/gui/windows/registerdialog.cpp4
-rw-r--r--src/gui/windows/selldialog.cpp4
-rw-r--r--src/gui/windows/serverdialog.cpp10
-rw-r--r--src/gui/windows/setupwindow.cpp4
-rw-r--r--src/gui/windows/shopwindow.cpp8
-rw-r--r--src/gui/windows/shortcutwindow.cpp8
-rw-r--r--src/gui/windows/skilldialog.cpp10
-rw-r--r--src/gui/windows/socialwindow.cpp82
-rw-r--r--src/gui/windows/statuswindow.cpp4
-rw-r--r--src/gui/windows/textcommandeditor.cpp10
-rw-r--r--src/gui/windows/unregisterdialog.cpp4
-rw-r--r--src/gui/windows/updaterwindow.cpp4
-rw-r--r--src/gui/windows/worldselectdialog.cpp4
-rw-r--r--src/guildmanager.cpp13
-rw-r--r--src/inventory.cpp4
-rw-r--r--src/main.cpp4
-rw-r--r--src/map.cpp17
-rw-r--r--src/maplayer.cpp6
-rw-r--r--src/net/charserverhandler.h5
-rw-r--r--src/net/ea/guildhandler.cpp11
-rw-r--r--src/net/ea/inventoryhandler.cpp11
-rw-r--r--src/net/ea/partyhandler.cpp8
-rw-r--r--src/net/eathena/generalhandler.cpp11
-rw-r--r--src/net/eathena/network.cpp5
-rw-r--r--src/net/tmwa/generalhandler.cpp11
-rw-r--r--src/net/tmwa/network.cpp5
-rw-r--r--src/particle/animationparticle.cpp5
-rw-r--r--src/particle/particlecontainer.cpp7
-rw-r--r--src/particle/rotationalparticle.cpp5
-rw-r--r--src/resources/beinginfo.cpp7
-rw-r--r--src/resources/db/itemdb.cpp4
-rw-r--r--src/resources/dye.cpp7
-rw-r--r--src/resources/mapreader.cpp8
-rw-r--r--src/resources/resourcemanager.cpp4
-rw-r--r--src/shopitem.cpp1
-rw-r--r--src/simpleanimation.cpp5
-rw-r--r--src/test/testmain.cpp4
-rw-r--r--src/text.cpp5
-rw-r--r--src/touchmanager.cpp8
-rw-r--r--src/utils/delete2.h30
-rw-r--r--src/utils/translation/translationmanager.cpp4
108 files changed, 505 insertions, 688 deletions
diff --git a/src/actormanager.cpp b/src/actormanager.cpp
index bc325abe8..2d7c3a11b 100644
--- a/src/actormanager.cpp
+++ b/src/actormanager.cpp
@@ -812,9 +812,7 @@ void ActorManager::clear()
}
for_actors
- {
delete *it;
- }
mActors.clear();
mDeleteActors.clear();
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 97424fbfb..930d7d61e 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -31,6 +31,8 @@
#include "resources/image.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
+
#include "debug.h"
bool AnimatedSprite::mEnableCache = false;
@@ -108,8 +110,7 @@ AnimatedSprite::~AnimatedSprite()
{
mDelayLoad->clearSprite();
ResourceManager::removeDelayLoad(mDelayLoad);
- delete mDelayLoad;
- mDelayLoad = nullptr;
+ delete2(mDelayLoad);
}
}
diff --git a/src/being/actorsprite.cpp b/src/being/actorsprite.cpp
index 9c1eeddc7..29fa1290c 100644
--- a/src/being/actorsprite.cpp
+++ b/src/being/actorsprite.cpp
@@ -37,6 +37,7 @@
#include "resources/resourcemanager.h"
#include "utils/checkutils.h"
+#include "utils/delete2.h"
#include "utils/timer.h"
#include "debug.h"
@@ -379,10 +380,7 @@ void ActorSprite::cleanupTargetCursors()
for (int type = TCT_NORMAL; type < NUM_TCT; type++)
{
if (targetCursor[type][size])
- {
- delete targetCursor[type][size];
- targetCursor[type][size] = nullptr;
- }
+ delete2(targetCursor[type][size])
}
}
}
diff --git a/src/being/being.cpp b/src/being/being.cpp
index 611263dff..d1a1d8906 100644
--- a/src/being/being.cpp
+++ b/src/being/being.cpp
@@ -70,6 +70,7 @@
#include "gui/widgets/tabs/langtab.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/timer.h"
@@ -232,17 +233,11 @@ Being::~Being()
delete [] mSpriteDraw;
mSpriteDraw = nullptr;
- delete mSpeechBubble;
- mSpeechBubble = nullptr;
- delete mDispName;
- mDispName = nullptr;
- delete mText;
- mText = nullptr;
-
- delete mEmotionSprite;
- mEmotionSprite = nullptr;
- delete mAnimationEffect;
- mAnimationEffect = nullptr;
+ delete2(mSpeechBubble);
+ delete2(mDispName);
+ delete2(mText);
+ delete2(mEmotionSprite);
+ delete2(mAnimationEffect);
if (mOwner)
mOwner->unassignPet(this);
@@ -469,7 +464,6 @@ void Being::setSpeech(const std::string &text, const std::string &channel,
if (speech == TEXT_OVERHEAD && userPalette)
{
delete mText;
-
mText = new Text(mSpeech,
getPixelX(), getPixelY() - getHeight(),
Graphics::CENTER,
@@ -821,14 +815,9 @@ void Being::setShowName(const bool doShowName)
mShowName = doShowName;
if (doShowName)
- {
showName();
- }
else
- {
- delete mDispName;
- mDispName = nullptr;
- }
+ delete2(mDispName)
}
void Being::setGuildName(const std::string &name)
@@ -1365,10 +1354,7 @@ void Being::logic()
// Remove text and speechbubbles if speech boxes aren't being used
if (mSpeechTime == 0 && mText)
- {
- delete mText;
- mText = nullptr;
- }
+ delete2(mText)
const int time = tick_time * MILLISECONDS_IN_A_TICK;
if (mEmotionSprite)
@@ -1378,10 +1364,7 @@ void Being::logic()
{
mAnimationEffect->update(time);
if (mAnimationEffect->isTerminated())
- {
- delete mAnimationEffect;
- mAnimationEffect = nullptr;
- }
+ delete2(mAnimationEffect)
}
int frameCount = static_cast<int>(getFrameCount());
@@ -1453,10 +1436,7 @@ void Being::logic()
{
mEmotionTime--;
if (mEmotionTime == 0)
- {
- delete mEmotionSprite;
- mEmotionSprite = nullptr;
- }
+ delete2(mEmotionSprite)
}
ActorSprite::logic();
@@ -1695,8 +1675,7 @@ void Being::drawSpeech(const int offsetX, const int offsetY)
else if (mSpeechTime > 0 && (speech == NAME_IN_BUBBLE ||
speech == NO_NAME_IN_BUBBLE))
{
- delete mText;
- mText = nullptr;
+ delete2(mText)
mSpeechBubble->setPosition(px - (mSpeechBubble->getWidth() / 2),
py - getHeight() - (mSpeechBubble->getHeight()));
@@ -1717,9 +1696,7 @@ void Being::drawSpeech(const int offsetX, const int offsetY)
else if (speech == NO_SPEECH)
{
mSpeechBubble->setVisible(false);
-
- delete mText;
- mText = nullptr;
+ delete2(mText)
}
}
@@ -1831,8 +1808,7 @@ void Being::showName()
if (mName.empty())
return;
- delete mDispName;
- mDispName = nullptr;
+ delete2(mDispName);
if (mHideErased && player_relations.getRelation(mName) ==
PlayerRelation::ERASED)
@@ -2967,8 +2943,7 @@ void Being::setEmote(const uint8_t emotion, const int emote_time)
const int emotionIndex = emotion - 1;
if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast())
{
- delete mEmotionSprite;
- mEmotionSprite = nullptr;
+ delete2(mEmotionSprite)
const EmoteInfo *const info = EmoteDB::get2(emotionIndex, true);
if (info)
{
@@ -3076,8 +3051,7 @@ void Being::removeSpecialEffect()
mChildParticleEffects.removeLocally(mSpecialParticle);
mSpecialParticle = nullptr;
}
- delete mAnimationEffect;
- mAnimationEffect = nullptr;
+ delete2(mAnimationEffect);
}
void Being::updateAwayEffect()
@@ -3322,9 +3296,7 @@ void Being::setMap(Map *const map)
void Being::removeAllItemsParticles()
{
FOR_EACH (SpriteParticleInfoIter, it, mSpriteParticles)
- {
delete (*it).second;
- }
mSpriteParticles.clear();
}
diff --git a/src/being/compoundsprite.cpp b/src/being/compoundsprite.cpp
index 63dd32fec..6c159821d 100644
--- a/src/being/compoundsprite.cpp
+++ b/src/being/compoundsprite.cpp
@@ -36,6 +36,7 @@
#include "resources/image.h"
#include "resources/imagehelper.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/sdlcheckutils.h"
#include "utils/timer.h"
@@ -252,8 +253,7 @@ void CompoundSprite::removeSprite(const int layer)
if (!mSprites.at(layer))
return;
- delete mSprites.at(layer);
- mSprites.at(layer) = nullptr;
+ delete2(mSprites.at(layer));
mNeedsRedraw = true;
}
@@ -268,8 +268,7 @@ void CompoundSprite::clear()
mNeedsRedraw = true;
delete_all(imagesCache);
imagesCache.clear();
- delete mCacheItem;
- mCacheItem = nullptr;
+ delete2(mCacheItem);
}
void CompoundSprite::ensureSize(size_t layerCount)
@@ -361,8 +360,7 @@ void CompoundSprite::redraw() const
drawSpritesSDL(graphics, posX, posY);
- delete graphics;
- graphics = nullptr;
+ delete2(graphics);
SDL_Surface *const surfaceA = MSDL_CreateRGBSurface(SDL_HWSURFACE,
BUFFER_WIDTH, BUFFER_HEIGHT, 32, rmask, gmask, bmask, amask);
diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp
index 2e09f1690..c774b985b 100644
--- a/src/being/localplayer.cpp
+++ b/src/being/localplayer.cpp
@@ -69,6 +69,7 @@
#include "resources/db/emotedb.h"
#include "resources/db/weaponsdb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/timer.h"
@@ -223,11 +224,9 @@ LocalPlayer::~LocalPlayer()
if (mAwayDialog)
{
soundManager.volumeRestore();
- delete mAwayDialog;
- mAwayDialog = nullptr;
+ delete2(mAwayDialog)
}
- delete mAwayListener;
- mAwayListener = nullptr;
+ delete2(mAwayListener);
}
void LocalPlayer::logic()
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index 728fe786f..12ce1e6d3 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -37,6 +37,8 @@
#include "net/net.h"
#include "net/playerhandler.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace PlayerInfo
@@ -422,10 +424,8 @@ bool isTalking()
void gameDestroyed()
{
- delete mInventory;
- mInventory = nullptr;
- delete mEquipment;
- mEquipment = nullptr;
+ delete2(mInventory);
+ delete2(mEquipment);
}
void stateChange(const int state)
diff --git a/src/beingequipbackend.cpp b/src/beingequipbackend.cpp
index 03d882665..3f5f627a8 100644
--- a/src/beingequipbackend.cpp
+++ b/src/beingequipbackend.cpp
@@ -25,6 +25,8 @@
#include "net/inventoryhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
+
#include "debug.h"
BeingEquipBackend::BeingEquipBackend(Being *const being)
@@ -51,19 +53,13 @@ BeingEquipBackend::BeingEquipBackend(Being *const being)
BeingEquipBackend::~BeingEquipBackend()
{
for (int i = 0; i < EQUIPMENT_SIZE; i++)
- {
- delete mEquipment[i];
- mEquipment[i] = nullptr;
- }
+ delete2(mEquipment[i])
}
void BeingEquipBackend::clear()
{
for (int i = 0; i < EQUIPMENT_SIZE; i++)
- {
- delete mEquipment[i];
- mEquipment[i] = nullptr;
- }
+ delete2(mEquipment[i])
}
void BeingEquipBackend::setEquipment(const int index, Item *const item)
diff --git a/src/client.cpp b/src/client.cpp
index 70f27f773..9aded7682 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -110,6 +110,7 @@
#include "utils/base64.h"
#include "utils/cpu.h"
+#include "utils/delete2.h"
#include "utils/files.h"
#include "utils/fuzzer.h"
#include "utils/gettext.h"
@@ -821,12 +822,9 @@ void Client::gameClear()
eventsManager.shutdown();
- delete setupWindow;
- setupWindow = nullptr;
- delete helpWindow;
- helpWindow = nullptr;
- delete didYouKnowWindow;
- didYouKnowWindow = nullptr;
+ delete2(setupWindow);
+ delete2(helpWindow);
+ delete2(didYouKnowWindow);
stopTimers();
@@ -853,33 +851,24 @@ void Client::gameClear()
Net::getChatHandler()->clear();
#ifdef USE_MUMBLE
- delete mumbleManager;
- mumbleManager = nullptr;
+ delete2(mumbleManager);
#endif
PlayerInfo::deinit();
// Before config.write() since it writes the shortcuts to the config
for (unsigned f = 0; f < SHORTCUT_TABS; f ++)
- {
- delete itemShortcut[f];
- itemShortcut[f] = nullptr;
- }
- delete emoteShortcut;
- emoteShortcut = nullptr;
- delete dropShortcut;
- dropShortcut = nullptr;
+ delete2(itemShortcut[f])
+ delete2(emoteShortcut);
+ delete2(dropShortcut);
player_relations.store();
if (logger)
logger->log1("Quitting2");
- delete mCurrentDialog;
- mCurrentDialog = nullptr;
-
- delete gui;
- gui = nullptr;
+ delete2(mCurrentDialog);
+ delete2(gui);
if (Net::getInventoryHandler())
Net::getInventoryHandler()->clear();
@@ -887,14 +876,12 @@ void Client::gameClear()
if (logger)
logger->log1("Quitting3");
- delete mainGraphics;
- mainGraphics = nullptr;
+ delete2(mainGraphics);
if (imageHelper != surfaceImageHelper)
delete surfaceImageHelper;
surfaceImageHelper = nullptr;
- delete imageHelper;
- imageHelper = nullptr;
+ delete2(imageHelper);
if (logger)
logger->log1("Quitting4");
@@ -925,11 +912,8 @@ void Client::gameClear()
if (logger)
logger->log1("Quitting9");
- delete userPalette;
- userPalette = nullptr;
-
- delete joystick;
- joystick = nullptr;
+ delete2(userPalette);
+ delete2(joystick);
keyboard.deinit();
@@ -961,8 +945,7 @@ void Client::gameClear()
logger->log("textures left: %d", textures_count);
#endif
- delete chatLogger;
- chatLogger = nullptr;
+ delete2(chatLogger);
TranslationManager::close();
}
@@ -1174,8 +1157,7 @@ int Client::gameExec()
if (mOldState == STATE_GAME)
{
- delete mGame;
- mGame = nullptr;
+ delete2(mGame);
Game::clearInstance();
ResourceManager *const resman = ResourceManager::getInstance();
if (resman)
@@ -1198,8 +1180,7 @@ int Client::gameExec()
mOldState = mState;
// Get rid of the dialog of the previous state
- delete mCurrentDialog;
- mCurrentDialog = nullptr;
+ delete2(mCurrentDialog);
// State has changed, while the quitDialog was active, it might
// not be correct anymore
if (mQuitDialog)
@@ -1577,23 +1558,15 @@ int Client::gameExec()
chatLogger->setServerName(mServerName);
#ifdef ANDROID
- delete mCloseButton;
- mCloseButton = nullptr;
-#endif
- delete mSetupButton;
- mSetupButton = nullptr;
- delete mVideoButton;
- mVideoButton = nullptr;
- delete mThemesButton;
- mThemesButton = nullptr;
- delete mAboutButton;
- mAboutButton = nullptr;
- delete mHelpButton;
- mHelpButton = nullptr;
- delete mPerfomanceButton;
- mPerfomanceButton = nullptr;
- delete mDesktop;
- mDesktop = nullptr;
+ delete2(mCloseButton);
+#endif
+ delete2(mSetupButton);
+ delete2(mVideoButton);
+ delete2(mThemesButton);
+ delete2(mAboutButton);
+ delete2(mHelpButton);
+ delete2(mPerfomanceButton);
+ delete2(mDesktop);
mCurrentDialog = nullptr;
diff --git a/src/commands.cpp b/src/commands.cpp
index 864dee6c4..de4c03012 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -77,6 +77,7 @@
#include "resources/db/itemdb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/process.h"
#include "utils/timer.h"
@@ -1319,8 +1320,7 @@ static int uploadUpdate(void *ptr,
}
}
}
- delete info->upload;
- info->upload = nullptr;
+ delete2(info->upload);
delete info;
return 0;
}
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 54420a9f3..550c61243 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -27,6 +27,7 @@
#include "listeners/configlistener.h"
+#include "utils/delete2.h"
#include "utils/paths.h"
#include "debug.h"
@@ -367,8 +368,7 @@ void Configuration::cleanDefaults()
delete (iter->second);
}
mDefaultsData->clear();
- delete mDefaultsData;
- mDefaultsData = nullptr;
+ delete2(mDefaultsData);
}
}
diff --git a/src/depricatedevent.cpp b/src/depricatedevent.cpp
index fc499c47b..3f8abad00 100644
--- a/src/depricatedevent.cpp
+++ b/src/depricatedevent.cpp
@@ -25,6 +25,8 @@
#include "listeners/depricatedlistener.h"
+#include "utils/delete2.h"
+
#include "debug.h"
DepricatedListenMap DepricatedEvent::mBindings;
@@ -34,8 +36,7 @@ DepricatedEvent::~DepricatedEvent()
VariableMap::iterator it = mData.begin();
while (it != mData.end())
{
- delete it->second;
- it->second = nullptr;
+ delete2(it->second);
++it;
}
}
diff --git a/src/game.cpp b/src/game.cpp
index f51fa8707..33369bf97 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -98,6 +98,7 @@
#include "resources/db/mapdb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/langs.h"
#include "utils/mkdir.h"
@@ -323,8 +324,6 @@ static void createGuiWindows()
Net::getGeneralHandler()->gameStarted();
}
-#define del_0(X) { delete X; X = nullptr; }
-
/**
* Destroy all the globally accessible gui windows
*/
@@ -341,37 +340,37 @@ static void destroyGuiWindows()
if (guildManager)
guildManager->clear();
- del_0(windowMenu);
- del_0(localChatTab) // Need to do this first, so it can remove itself
- del_0(debugChatTab)
- del_0(tradeChatTab)
- del_0(battleChatTab)
- del_0(langChatTab)
- del_0(gmChatTab);
+ delete2(windowMenu);
+ delete2(localChatTab) // Need to do this first, so it can remove itself
+ delete2(debugChatTab)
+ delete2(tradeChatTab)
+ delete2(battleChatTab)
+ delete2(langChatTab)
+ delete2(gmChatTab);
logger->log("start deleting");
- del_0(emoteWindow);
- del_0(chatWindow)
+ delete2(emoteWindow);
+ delete2(chatWindow)
logger->log("end deleting");
- del_0(statusWindow)
- del_0(miniStatusWindow)
- del_0(inventoryWindow)
- del_0(shopWindow)
- del_0(skillDialog)
- del_0(minimap)
- del_0(equipmentWindow)
- del_0(beingEquipmentWindow)
- del_0(tradeWindow)
- del_0(debugWindow)
- del_0(itemShortcutWindow)
- del_0(emoteShortcutWindow)
- del_0(outfitWindow)
- del_0(socialWindow)
- del_0(dropShortcutWindow);
- del_0(spellShortcutWindow);
- del_0(botCheckerWindow);
- del_0(questsWindow);
- del_0(whoIsOnline);
- del_0(killStats);
+ delete2(statusWindow)
+ delete2(miniStatusWindow)
+ delete2(inventoryWindow)
+ delete2(shopWindow)
+ delete2(skillDialog)
+ delete2(minimap)
+ delete2(equipmentWindow)
+ delete2(beingEquipmentWindow)
+ delete2(tradeWindow)
+ delete2(debugWindow)
+ delete2(itemShortcutWindow)
+ delete2(emoteShortcutWindow)
+ delete2(outfitWindow)
+ delete2(socialWindow)
+ delete2(dropShortcutWindow);
+ delete2(spellShortcutWindow);
+ delete2(botCheckerWindow);
+ delete2(questsWindow);
+ delete2(whoIsOnline);
+ delete2(killStats);
if (auctionManager && AuctionManager::getEnableAuctionBot())
auctionManager->reload();
@@ -458,20 +457,20 @@ Game::~Game()
AnimatedSprite::setEnableCache(false);
- del_0(actorManager)
+ delete2(actorManager)
if (client->getState() != STATE_CHANGE_MAP)
- del_0(player_node)
- del_0(commandHandler)
- del_0(effectManager)
- del_0(particleEngine)
- del_0(viewport)
- del_0(mCurrentMap)
- del_0(spellManager)
- del_0(spellShortcut)
- del_0(auctionManager)
- del_0(guildManager)
+ delete2(player_node)
+ delete2(commandHandler)
+ delete2(effectManager)
+ delete2(particleEngine)
+ delete2(viewport)
+ delete2(mCurrentMap)
+ delete2(spellManager)
+ delete2(spellShortcut)
+ delete2(auctionManager)
+ delete2(guildManager)
#ifdef USE_MUMBLE
- del_0(mumbleManager)
+ delete2(mumbleManager)
#endif
Being::clearCache();
diff --git a/src/gui/font.cpp b/src/gui/font.cpp
index cf3116631..acc27d4ab 100644
--- a/src/gui/font.cpp
+++ b/src/gui/font.cpp
@@ -76,6 +76,7 @@
#include "resources/resourcemanager.h"
#include "resources/surfaceimagehelper.h"
+#include "utils/delete2.h"
#include "utils/paths.h"
#include "utils/sdlcheckutils.h"
#include "utils/stringutils.h"
@@ -163,8 +164,7 @@ SDLTextChunk::SDLTextChunk(const std::string &text0, const Color &color0,
SDLTextChunk::~SDLTextChunk()
{
- delete img;
- img = nullptr;
+ delete2(img);
#ifdef UNITTESTS
sdlTextChunkCnt --;
#endif
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 761810c1a..9a50583b9 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -95,6 +95,7 @@
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
#include "utils/langs.h"
#include "utils/timer.h"
@@ -290,8 +291,7 @@ void Gui::postInit(Graphics *const graphics)
Gui::~Gui()
{
config.removeListeners(mConfigListener);
- delete mConfigListener;
- mConfigListener = nullptr;
+ delete2(mConfigListener);
if (mMouseCursors)
{
@@ -299,31 +299,22 @@ Gui::~Gui()
mMouseCursors = nullptr;
}
- delete mGuiFont;
- mGuiFont = nullptr;
- delete boldFont;
- boldFont = nullptr;
- delete mHelpFont;
- mHelpFont = nullptr;
- delete mSecureFont;
- mSecureFont = nullptr;
- delete mInfoParticleFont;
- mInfoParticleFont = nullptr;
- delete mNpcFont;
- mNpcFont = nullptr;
+ delete2(mGuiFont);
+ delete2(boldFont);
+ delete2(mHelpFont);
+ delete2(mSecureFont);
+ delete2(mInfoParticleFont);
+ delete2(mNpcFont);
delete getTop();
- delete guiInput;
- guiInput = nullptr;
+ delete2(guiInput);
- delete theme;
- theme = nullptr;
+ delete2(theme);
if (Widget::widgetExists(mTop))
setTop(nullptr);
- delete mFocusHandler;
- mFocusHandler = nullptr;
+ delete2(mFocusHandler);
}
void Gui::logic()
diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp
index b208ce960..6fa007e06 100644
--- a/src/gui/theme.cpp
+++ b/src/gui/theme.cpp
@@ -32,6 +32,7 @@
#include "resources/image.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/files.h"
#include "utils/physfstools.h"
@@ -121,10 +122,8 @@ Skin::~Skin()
mStickyImageDown = nullptr;
}
- delete mOptions;
- mOptions = nullptr;
- delete mBorder;
- mBorder = nullptr;
+ delete2(mOptions);
+ delete2(mBorder);
}
void Skin::updateAlpha(const float minimumOpacityAllowed)
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index ba11bdf95..df97a5673 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -35,6 +35,7 @@
#include "input/inputmanager.h"
#include "gui/gui.h"
+#include "gui/font.h"
#include "gui/popups/beingpopup.h"
#include "gui/popups/popupmenu.h"
@@ -42,7 +43,7 @@
#include "gui/windows/ministatuswindow.h"
-#include "gui/font.h"
+#include "utils/delete2.h"
#include "debug.h"
@@ -104,12 +105,9 @@ Viewport::~Viewport()
{
config.removeListeners(this);
CHECKLISTENERS
- delete mPopupMenu;
- mPopupMenu = nullptr;
- delete mBeingPopup;
- mBeingPopup = nullptr;
- delete mTextPopup;
- mTextPopup = nullptr;
+ delete2(mPopupMenu);
+ delete2(mBeingPopup);
+ delete2(mTextPopup);
}
void Viewport::setMap(Map *const map)
diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp
index dffcc7814..054a338aa 100644
--- a/src/gui/widgets/button.cpp
+++ b/src/gui/widgets/button.cpp
@@ -77,9 +77,10 @@
#include "gui/font.h"
#include "gui/gui.h"
-
#include "gui/rect.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int Button::mInstances = 0;
@@ -362,8 +363,7 @@ Button::~Button()
for (int mode = 0; mode < BUTTON_COUNT; mode ++)
theme->unload(button[mode]);
}
- delete mVertexes2;
- mVertexes2 = nullptr;
+ delete2(mVertexes2);
if (mImageSet)
{
mImageSet->decRef();
diff --git a/src/gui/widgets/characterdisplay.cpp b/src/gui/widgets/characterdisplay.cpp
index db2f2e2de..389b3f8cc 100644
--- a/src/gui/widgets/characterdisplay.cpp
+++ b/src/gui/widgets/characterdisplay.cpp
@@ -33,6 +33,7 @@
#include "gui/widgets/label.h"
#include "gui/widgets/layouthelper.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -77,8 +78,7 @@ CharacterDisplay::CharacterDisplay(const Widget2 *const widget,
CharacterDisplay::~CharacterDisplay()
{
- delete mPopup;
- mPopup = nullptr;
+ delete2(mPopup);
}
void CharacterDisplay::setCharacter(Net::Character *const character)
diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp
index d85bcccf4..67e027a96 100644
--- a/src/gui/widgets/dropshortcutcontainer.cpp
+++ b/src/gui/widgets/dropshortcutcontainer.cpp
@@ -28,6 +28,7 @@
#include "being/playerinfo.h"
+#include "gui/font.h"
#include "gui/viewport.h"
#include "gui/popups/itempopup.h"
@@ -36,7 +37,7 @@
#include "resources/image.h"
-#include "gui/font.h"
+#include "utils/delete2.h"
#include "debug.h"
@@ -81,8 +82,7 @@ DropShortcutContainer::~DropShortcutContainer()
mBackgroundImg->decRef();
mBackgroundImg = nullptr;
}
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
}
void DropShortcutContainer::setWidget2(const Widget2 *const widget)
diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp
index c0fcb8ecf..789d3e1aa 100644
--- a/src/gui/widgets/emotepage.cpp
+++ b/src/gui/widgets/emotepage.cpp
@@ -25,6 +25,8 @@
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace
@@ -55,8 +57,7 @@ EmotePage::~EmotePage()
mEmotes->decRef();
mEmotes = nullptr;
}
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void EmotePage::draw(Graphics *graphics)
diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp
index 3248f1884..6feed2b12 100644
--- a/src/gui/widgets/guitable.cpp
+++ b/src/gui/widgets/guitable.cpp
@@ -30,12 +30,13 @@
#include "input/keydata.h"
-#include "utils/dtor.h"
-
#include "listeners/actionlistener.h"
#include "render/graphics.h"
+#include "utils/delete2.h"
+#include "utils/dtor.h"
+
#include "debug.h"
float GuiTable::mAlpha = 1.0;
@@ -126,8 +127,7 @@ GuiTable::~GuiTable()
gui->removeDragged(this);
uninstallActionListeners();
- delete mModel;
- mModel = nullptr;
+ delete2(mModel);
}
const TableModel *GuiTable::getModel() const
diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp
index 1c6cf9ec3..ee2e35920 100644
--- a/src/gui/widgets/itemcontainer.cpp
+++ b/src/gui/widgets/itemcontainer.cpp
@@ -29,6 +29,7 @@
#include "being/playerinfo.h"
+#include "gui/font.h"
#include "gui/gui.h"
#include "gui/viewport.h"
@@ -46,9 +47,10 @@
#include "resources/image.h"
-#include "gui/font.h"
#include "listeners/selectionlistener.h"
+#include "utils/delete2.h"
+
#include <algorithm>
#include "debug.h"
@@ -218,8 +220,7 @@ ItemContainer::~ItemContainer()
if (theme)
theme->unload(mSkin);
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
delete []mShowMatrix;
}
diff --git a/src/gui/widgets/itemlinkhandler.cpp b/src/gui/widgets/itemlinkhandler.cpp
index 2cf27ae30..efc6ef175 100644
--- a/src/gui/widgets/itemlinkhandler.cpp
+++ b/src/gui/widgets/itemlinkhandler.cpp
@@ -39,6 +39,8 @@
#include "input/mouseinput.h"
+#include "utils/delete2.h"
+
#include <string>
#include "debug.h"
@@ -74,8 +76,7 @@ ItemLinkHandler::ItemLinkHandler() :
ItemLinkHandler::~ItemLinkHandler()
{
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
}
void ItemLinkHandler::handleLink(const std::string &link, MouseEvent *event)
diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp
index 33ae1890d..420eb5578 100644
--- a/src/gui/widgets/itemshortcutcontainer.cpp
+++ b/src/gui/widgets/itemshortcutcontainer.cpp
@@ -46,6 +46,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
ItemShortcutContainer::ItemShortcutContainer(Widget2 *const widget,
@@ -95,10 +97,8 @@ ItemShortcutContainer::~ItemShortcutContainer()
mBackgroundImg->decRef();
mBackgroundImg = nullptr;
}
- delete mItemPopup;
- mItemPopup = nullptr;
- delete mSpellPopup;
- mSpellPopup = nullptr;
+ delete2(mItemPopup);
+ delete2(mSpellPopup);
}
void ItemShortcutContainer::setWidget2(const Widget2 *const widget)
diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp
index 668334fd5..410c8188e 100644
--- a/src/gui/widgets/layout.cpp
+++ b/src/gui/widgets/layout.cpp
@@ -26,6 +26,8 @@
#include "gui/widgets/basiccontainer2.h"
+#include "utils/delete2.h"
+
#include <cassert>
#include "debug.h"
@@ -45,10 +47,7 @@ LayoutCell &ContainerPlacer::operator()
LayoutCell::~LayoutCell()
{
if (mType == ARRAY)
- {
- delete mArray;
- mArray = nullptr;
- }
+ delete2(mArray)
}
LayoutArray &LayoutCell::getArray()
diff --git a/src/gui/widgets/popup.cpp b/src/gui/widgets/popup.cpp
index a8bcec4ea..2116de113 100644
--- a/src/gui/widgets/popup.cpp
+++ b/src/gui/widgets/popup.cpp
@@ -27,6 +27,8 @@
#include "gui/viewport.h"
+#include "utils/delete2.h"
+
#include "debug.h"
Popup::Popup(const std::string &name,
@@ -72,8 +74,7 @@ Popup::~Popup()
{
logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str());
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
if (mSkin)
{
diff --git a/src/gui/widgets/progressbar.cpp b/src/gui/widgets/progressbar.cpp
index e2ff95228..ea4ef11bd 100644
--- a/src/gui/widgets/progressbar.cpp
+++ b/src/gui/widgets/progressbar.cpp
@@ -28,6 +28,8 @@
#include "gui/font.h"
#include "gui/gui.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int ProgressBar::mInstances = 0;
@@ -100,8 +102,7 @@ ProgressBar::~ProgressBar()
mSkin = nullptr;
}
Theme::unloadRect(mFillRect);
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void ProgressBar::logic()
diff --git a/src/gui/widgets/progressindicator.cpp b/src/gui/widgets/progressindicator.cpp
index 8e86417bd..c960ad075 100644
--- a/src/gui/widgets/progressindicator.cpp
+++ b/src/gui/widgets/progressindicator.cpp
@@ -28,6 +28,8 @@
#include "resources/animation.h"
#include "resources/imageset.h"
+#include "utils/delete2.h"
+
#include "debug.h"
ProgressIndicator::ProgressIndicator(Widget2 *const widget) :
@@ -54,8 +56,7 @@ ProgressIndicator::~ProgressIndicator()
if (gui)
gui->removeDragged(this);
- delete mIndicator;
- mIndicator = nullptr;
+ delete2(mIndicator);
}
void ProgressIndicator::logic()
diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp
index 95323a170..2efa144c9 100644
--- a/src/gui/widgets/scrollarea.cpp
+++ b/src/gui/widgets/scrollarea.cpp
@@ -72,6 +72,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int ScrollArea::instances = 0;
@@ -164,10 +166,8 @@ ScrollArea::~ScrollArea()
}
}
- delete mVertexes;
- mVertexes = nullptr;
- delete mVertexes2;
- mVertexes2 = nullptr;
+ delete2(mVertexes);
+ delete2(mVertexes2);
setContent(nullptr);
}
diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp
index b1bb1e867..49be84b88 100644
--- a/src/gui/widgets/shortcutcontainer.cpp
+++ b/src/gui/widgets/shortcutcontainer.cpp
@@ -26,6 +26,8 @@
#include "gui/gui.h"
+#include "utils/delete2.h"
+
#include "debug.h"
float ShortcutContainer::mAlpha = 1.0;
@@ -51,8 +53,7 @@ ShortcutContainer::~ShortcutContainer()
if (gui)
gui->removeDragged(this);
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void ShortcutContainer::widgetResized(const Event &event A_UNUSED)
diff --git a/src/gui/widgets/slider.cpp b/src/gui/widgets/slider.cpp
index cf9aad03d..e440631ad 100644
--- a/src/gui/widgets/slider.cpp
+++ b/src/gui/widgets/slider.cpp
@@ -76,6 +76,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
ImageRect Slider::buttons[2];
@@ -130,8 +132,7 @@ Slider::~Slider()
if (gui)
gui->removeDragged(this);
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
mInstances--;
if (mInstances == 0)
{
diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp
index add394a64..e86376812 100644
--- a/src/gui/widgets/spellshortcutcontainer.cpp
+++ b/src/gui/widgets/spellshortcutcontainer.cpp
@@ -36,6 +36,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
SpellShortcutContainer::SpellShortcutContainer(Widget2 *const widget,
@@ -78,8 +80,7 @@ SpellShortcutContainer::~SpellShortcutContainer()
if (mBackgroundImg)
mBackgroundImg->decRef();
mBackgroundImg = nullptr;
- delete mSpellPopup;
- mSpellPopup = nullptr;
+ delete2(mSpellPopup);
}
void SpellShortcutContainer::setWidget2(const Widget2 *const widget)
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index 3cb6cb302..cf55fa10b 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -75,6 +75,8 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tabs/tab.h"
+#include "utils/delete2.h"
+
#include "debug.h"
TabbedArea::TabbedArea(const Widget2 *const widget) :
@@ -127,21 +129,14 @@ TabbedArea::~TabbedArea()
remove(mTabContainer);
remove(mWidgetContainer);
- delete mTabContainer;
- mTabContainer = nullptr;
- delete mWidgetContainer;
- mWidgetContainer = nullptr;
+ delete2(mTabContainer);
+ delete2(mWidgetContainer);
for (size_t i = 0, sz = mTabsToDelete.size(); i < sz; i++)
- {
- delete mTabsToDelete[i];
- mTabsToDelete[i] = nullptr;
- }
+ delete2(mTabsToDelete[i])
- delete mArrowButton[0];
- mArrowButton[0] = nullptr;
- delete mArrowButton[1];
- mArrowButton[1] = nullptr;
+ delete2(mArrowButton[0]);
+ delete2(mArrowButton[1]);
}
void TabbedArea::enableScrollButtons(const bool enable)
diff --git a/src/gui/widgets/tabs/chattab.cpp b/src/gui/widgets/tabs/chattab.cpp
index 8fe9d707b..e52f935b3 100644
--- a/src/gui/widgets/tabs/chattab.cpp
+++ b/src/gui/widgets/tabs/chattab.cpp
@@ -45,6 +45,7 @@
#include "resources/db/itemdb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -85,10 +86,8 @@ ChatTab::~ChatTab()
if (chatWindow)
chatWindow->removeTab(this);
- delete mTextOutput;
- mTextOutput = nullptr;
- delete mScrollArea;
- mScrollArea = nullptr;
+ delete2(mTextOutput);
+ delete2(mScrollArea);
}
void ChatTab::chatLog(std::string line, Own own,
diff --git a/src/gui/widgets/tabs/setup_audio.cpp b/src/gui/widgets/tabs/setup_audio.cpp
index 6cf675635..89a9594c1 100644
--- a/src/gui/widgets/tabs/setup_audio.cpp
+++ b/src/gui/widgets/tabs/setup_audio.cpp
@@ -35,6 +35,7 @@
#include "gui/widgets/layouthelper.h"
#include "gui/widgets/scrollarea.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -160,11 +161,8 @@ Setup_Audio::Setup_Audio(const Widget2 *const widget) :
Setup_Audio::~Setup_Audio()
{
- delete mSoundModel;
- mSoundModel = nullptr;
-
- delete mChannelsList;
- mChannelsList = nullptr;
+ delete2(mSoundModel);
+ delete2(mChannelsList);
}
void Setup_Audio::apply()
diff --git a/src/gui/widgets/tabs/setup_colors.cpp b/src/gui/widgets/tabs/setup_colors.cpp
index eb7e695f4..00537ad05 100644
--- a/src/gui/widgets/tabs/setup_colors.cpp
+++ b/src/gui/widgets/tabs/setup_colors.cpp
@@ -34,6 +34,7 @@
#include "gui/widgets/textfield.h"
#include "gui/widgets/textpreview.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -198,15 +199,9 @@ Setup_Colors::Setup_Colors(const Widget2 *const widget) :
Setup_Colors::~Setup_Colors()
{
if (mPreviewBox && mPreviewBox->getContent() == mPreview)
- {
- delete mTextPreview;
- mTextPreview = nullptr;
- }
+ delete2(mTextPreview)
else
- {
- delete mPreview;
- mPreview = nullptr;
- }
+ delete2(mPreview)
}
void Setup_Colors::action(const ActionEvent &event)
diff --git a/src/gui/widgets/tabs/setup_input.cpp b/src/gui/widgets/tabs/setup_input.cpp
index b04937881..a29e0d797 100644
--- a/src/gui/widgets/tabs/setup_input.cpp
+++ b/src/gui/widgets/tabs/setup_input.cpp
@@ -41,6 +41,8 @@
#include "gui/models/listmodel.h"
+#include "utils/delete2.h"
+
#include "debug.h"
static int selectedData = 0;
@@ -169,21 +171,14 @@ Setup_Input::Setup_Input(const Widget2 *const widget) :
Setup_Input::~Setup_Input()
{
- delete mKeyList;
- mKeyList = nullptr;
- delete mKeyListModel;
- mKeyListModel = nullptr;
-
- delete mAssignKeyButton;
- mAssignKeyButton = nullptr;
- delete mUnassignKeyButton;
- mUnassignKeyButton = nullptr;
- delete mResetKeysButton;
- mResetKeysButton = nullptr;
+ delete2(mKeyList);
+ delete2(mKeyListModel);
+ delete2(mAssignKeyButton);
+ delete2(mUnassignKeyButton);
+ delete2(mResetKeysButton);
delete [] mActionDataSize;
mActionDataSize = nullptr;
- delete mScrollArea;
- mScrollArea = nullptr;
+ delete2(mScrollArea);
}
void Setup_Input::apply()
diff --git a/src/gui/widgets/tabs/setup_joystick.cpp b/src/gui/widgets/tabs/setup_joystick.cpp
index b3d7b78b9..4d2845656 100644
--- a/src/gui/widgets/tabs/setup_joystick.cpp
+++ b/src/gui/widgets/tabs/setup_joystick.cpp
@@ -34,6 +34,7 @@
#include "gui/widgets/label.h"
#include "gui/widgets/layouthelper.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -99,8 +100,7 @@ Setup_Joystick::Setup_Joystick(const Widget2 *const widget) :
Setup_Joystick::~Setup_Joystick()
{
- delete mNamesModel;
- mNamesModel = nullptr;
+ delete2(mNamesModel);
}
void Setup_Joystick::action(const ActionEvent &event)
diff --git a/src/gui/widgets/tabs/setup_other.cpp b/src/gui/widgets/tabs/setup_other.cpp
index 12cb614cd..ed8ba11ad 100644
--- a/src/gui/widgets/tabs/setup_other.cpp
+++ b/src/gui/widgets/tabs/setup_other.cpp
@@ -31,6 +31,7 @@
#include "configuration.h"
#include "map.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -404,12 +405,9 @@ Setup_Other::Setup_Other(const Widget2 *const widget) :
Setup_Other::~Setup_Other()
{
- delete mProxyTypeList;
- mProxyTypeList = nullptr;
- delete mShortcutsList;
- mShortcutsList = nullptr;
- delete mDensityList;
- mDensityList = nullptr;
+ delete2(mProxyTypeList);
+ delete2(mShortcutsList);
+ delete2(mDensityList);
}
void Setup_Other::apply()
diff --git a/src/gui/widgets/tabs/setup_perfomance.cpp b/src/gui/widgets/tabs/setup_perfomance.cpp
index 5a0566ec2..dad054e83 100644
--- a/src/gui/widgets/tabs/setup_perfomance.cpp
+++ b/src/gui/widgets/tabs/setup_perfomance.cpp
@@ -28,6 +28,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/setupitem.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -159,6 +160,5 @@ Setup_Perfomance::Setup_Perfomance(const Widget2 *const widget) :
Setup_Perfomance::~Setup_Perfomance()
{
- delete mTexturesList;
- mTexturesList = nullptr;
+ delete2(mTexturesList);
}
diff --git a/src/gui/widgets/tabs/setup_relations.cpp b/src/gui/widgets/tabs/setup_relations.cpp
index ca060477f..77a758cb4 100644
--- a/src/gui/widgets/tabs/setup_relations.cpp
+++ b/src/gui/widgets/tabs/setup_relations.cpp
@@ -37,6 +37,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/guitable.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -81,10 +82,8 @@ public:
~PlayerTableModel()
{
freeWidgets();
- delete mListModel;
- mListModel = nullptr;
- delete mPlayers;
- mPlayers = nullptr;
+ delete2(mListModel)
+ delete2(mPlayers)
}
int getRows() const override final
@@ -159,9 +158,7 @@ public:
void freeWidgets()
{
- delete mPlayers;
- mPlayers = nullptr;
-
+ delete2(mPlayers)
delete_all(mWidgets);
mWidgets.clear();
}
@@ -266,8 +263,7 @@ Setup_Relations::Setup_Relations(const Widget2 *const widget) :
Setup_Relations::~Setup_Relations()
{
player_relations.removeListener(this);
- delete mIgnoreActionChoicesModel;
- mIgnoreActionChoicesModel = nullptr;
+ delete2(mIgnoreActionChoicesModel);
}
diff --git a/src/gui/widgets/tabs/setup_theme.cpp b/src/gui/widgets/tabs/setup_theme.cpp
index 424828694..9b23fc3c3 100644
--- a/src/gui/widgets/tabs/setup_theme.cpp
+++ b/src/gui/widgets/tabs/setup_theme.cpp
@@ -37,6 +37,7 @@
#include "configuration.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "resources/resourcemanager.h"
@@ -371,26 +372,13 @@ Setup_Theme::Setup_Theme(const Widget2 *const widget) :
Setup_Theme::~Setup_Theme()
{
- delete mInfo;
- mInfo = nullptr;
-
- delete mThemesModel;
- mThemesModel = nullptr;
-
- delete mFontsModel;
- mFontsModel = nullptr;
-
- delete mFontSizeListModel;
- mFontSizeListModel = nullptr;
-
- delete mNpcFontSizeListModel;
- mNpcFontSizeListModel = nullptr;
-
- delete mLangListModel;
- mLangListModel = nullptr;
-
- delete mInfo;
- mInfo = nullptr;
+ delete2(mInfo);
+ delete2(mThemesModel);
+ delete2(mFontsModel);
+ delete2(mFontSizeListModel);
+ delete2(mNpcFontSizeListModel);
+ delete2(mLangListModel);
+ delete2(mInfo);
}
void Setup_Theme::updateInfo()
diff --git a/src/gui/widgets/tabs/setup_touch.cpp b/src/gui/widgets/tabs/setup_touch.cpp
index fb50ab4d5..eab39ccb0 100644
--- a/src/gui/widgets/tabs/setup_touch.cpp
+++ b/src/gui/widgets/tabs/setup_touch.cpp
@@ -27,6 +27,7 @@
#include "gui/widgets/setuptouchitem.h"
#include "gui/widgets/scrollarea.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -126,10 +127,7 @@ Setup_Touch::Setup_Touch(const Widget2 *const widget) :
Setup_Touch::~Setup_Touch()
{
- delete mSizeList;
- mSizeList = nullptr;
- delete mFormatList;
- mFormatList = nullptr;
- delete mActionsList;
- mActionsList = nullptr;
+ delete2(mSizeList);
+ delete2(mFormatList);
+ delete2(mActionsList);
}
diff --git a/src/gui/widgets/tabs/setup_video.cpp b/src/gui/widgets/tabs/setup_video.cpp
index 416ae8c3c..dfe14fa2c 100644
--- a/src/gui/widgets/tabs/setup_video.cpp
+++ b/src/gui/widgets/tabs/setup_video.cpp
@@ -41,6 +41,7 @@
#include "render/rendererslistsdl.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/sdlhelper.h"
@@ -309,14 +310,10 @@ Setup_Video::Setup_Video(const Widget2 *const widget) :
Setup_Video::~Setup_Video()
{
- delete mModeListModel;
- mModeListModel = nullptr;
- delete mModeList;
- mModeList = nullptr;
- delete mOpenGLListModel;
- mOpenGLListModel = nullptr;
- delete mDialog;
- mDialog = nullptr;
+ delete2(mModeListModel);
+ delete2(mModeList);
+ delete2(mOpenGLListModel);
+ delete2(mDialog);
}
void Setup_Video::apply()
diff --git a/src/gui/widgets/tabs/setup_visual.cpp b/src/gui/widgets/tabs/setup_visual.cpp
index 860b1d516..eb6591f9f 100644
--- a/src/gui/widgets/tabs/setup_visual.cpp
+++ b/src/gui/widgets/tabs/setup_visual.cpp
@@ -28,6 +28,7 @@
#include "client.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -215,18 +216,12 @@ Setup_Visual::Setup_Visual(const Widget2 *const widget) :
Setup_Visual::~Setup_Visual()
{
- delete mSpeachList;
- mSpeachList = nullptr;
- delete mAmbientFxList;
- mAmbientFxList = nullptr;
- delete mParticleList;
- mParticleList = nullptr;
- delete mParticleTypeList;
- mParticleTypeList = nullptr;
- delete mVSyncList;
- mVSyncList = nullptr;
- delete mScaleList;
- mScaleList = nullptr;
+ delete2(mSpeachList);
+ delete2(mAmbientFxList);
+ delete2(mParticleList);
+ delete2(mParticleTypeList);
+ delete2(mVSyncList);
+ delete2(mScaleList);
}
void Setup_Visual::apply()
diff --git a/src/gui/widgets/tabs/setuptabscroll.cpp b/src/gui/widgets/tabs/setuptabscroll.cpp
index 9c185b2bb..cd169e0bf 100644
--- a/src/gui/widgets/tabs/setuptabscroll.cpp
+++ b/src/gui/widgets/tabs/setuptabscroll.cpp
@@ -24,6 +24,8 @@
#include "gui/widgets/setupitem.h"
#include "gui/widgets/vertcontainer.h"
+#include "utils/delete2.h"
+
#include "debug.h"
SetupTabScroll::SetupTabScroll(const Widget2 *const widget) :
@@ -41,10 +43,7 @@ SetupTabScroll::SetupTabScroll(const Widget2 *const widget) :
SetupTabScroll::~SetupTabScroll()
{
mScroll = nullptr;
-
- delete mContainer;
- mContainer = nullptr;
-
+ delete2(mContainer);
removeItems();
}
diff --git a/src/gui/widgets/tabs/tab.cpp b/src/gui/widgets/tabs/tab.cpp
index 32d0cf2a6..c2a6c0207 100644
--- a/src/gui/widgets/tabs/tab.cpp
+++ b/src/gui/widgets/tabs/tab.cpp
@@ -75,6 +75,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int Tab::mInstances = 0;
@@ -129,16 +131,14 @@ Tab::~Tab()
theme->unload(tabImg[mode]);
}
- delete mLabel;
- mLabel = nullptr;
+ delete2(mLabel);
if (mImage)
{
mImage->decRef();
mImage = nullptr;
}
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void Tab::init()
diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp
index d1f19785f..f89d2ead2 100644
--- a/src/gui/widgets/textfield.cpp
+++ b/src/gui/widgets/textfield.cpp
@@ -78,6 +78,7 @@
#include "resources/image.h"
#include "utils/copynpaste.h"
+#include "utils/delete2.h"
#include "utils/timer.h"
#undef DELETE // Win32 compatibility hack
@@ -154,8 +155,7 @@ TextField::~TextField()
if (gui)
gui->removeDragged(this);
- delete mPopupMenu;
- mPopupMenu = nullptr;
+ delete2(mPopupMenu);
instances--;
if (instances == 0)
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 4f8bc88b3..9e032f75b 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -82,6 +82,8 @@
#include "resources/cursor.h"
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
const int resizeMask = 8 + 4 + 2 + 1;
@@ -219,8 +221,7 @@ Window::~Window()
saveWindowState();
- delete mLayout;
- mLayout = nullptr;
+ delete2(mLayout);
while (!mWidgets.empty())
delete mWidgets.front();
@@ -228,8 +229,7 @@ Window::~Window()
mWidgets.clear();
removeWidgetListener(this);
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
windowInstances--;
@@ -1262,8 +1262,7 @@ void Window::reflowLayout(int w, int h)
return;
mLayout->reflow(w, h);
- delete mLayout;
- mLayout = nullptr;
+ delete2(mLayout);
setContentSize(w, h);
}
diff --git a/src/gui/windowmenu.cpp b/src/gui/windowmenu.cpp
index 2431a35ea..910bba705 100644
--- a/src/gui/windowmenu.cpp
+++ b/src/gui/windowmenu.cpp
@@ -34,6 +34,7 @@
#include "gui/widgets/button.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -171,8 +172,7 @@ WindowMenu::~WindowMenu()
config.removeListener("autohideButtons", this);
CHECKLISTENERS
- delete mTextPopup;
- mTextPopup = nullptr;
+ delete2(mTextPopup);
for (std::map <std::string, ButtonInfo*>::iterator
it = mButtonNames.begin(),
it_end = mButtonNames.end(); it != it_end; ++it)
diff --git a/src/gui/windows/buydialog.cpp b/src/gui/windows/buydialog.cpp
index 86e819121..8bece77ef 100644
--- a/src/gui/windows/buydialog.cpp
+++ b/src/gui/windows/buydialog.cpp
@@ -47,6 +47,7 @@
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <algorithm>
@@ -302,9 +303,7 @@ void BuyDialog::init()
BuyDialog::~BuyDialog()
{
- delete mShopItems;
- mShopItems = nullptr;
-
+ delete2(mShopItems);
instances.remove(this);
}
diff --git a/src/gui/windows/changeemaildialog.cpp b/src/gui/windows/changeemaildialog.cpp
index b8f9c1fd2..ce9ec84e8 100644
--- a/src/gui/windows/changeemaildialog.cpp
+++ b/src/gui/windows/changeemaildialog.cpp
@@ -35,6 +35,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <string>
@@ -105,8 +106,7 @@ ChangeEmailDialog::ChangeEmailDialog(LoginData *const data):
ChangeEmailDialog::~ChangeEmailDialog()
{
- delete mWrongDataNoticeListener;
- mWrongDataNoticeListener = nullptr;
+ delete2(mWrongDataNoticeListener);
}
void ChangeEmailDialog::action(const ActionEvent &event)
diff --git a/src/gui/windows/changepassworddialog.cpp b/src/gui/windows/changepassworddialog.cpp
index 05c7a9309..051fa6434 100644
--- a/src/gui/windows/changepassworddialog.cpp
+++ b/src/gui/windows/changepassworddialog.cpp
@@ -36,6 +36,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <string>
@@ -84,8 +85,7 @@ ChangePasswordDialog::ChangePasswordDialog(LoginData *const data):
ChangePasswordDialog::~ChangePasswordDialog()
{
- delete mWrongDataNoticeListener;
- mWrongDataNoticeListener = nullptr;
+ delete2(mWrongDataNoticeListener);
}
void ChangePasswordDialog::action(const ActionEvent &event)
diff --git a/src/gui/windows/charcreatedialog.cpp b/src/gui/windows/charcreatedialog.cpp
index 53b4b55ff..cf69af099 100644
--- a/src/gui/windows/charcreatedialog.cpp
+++ b/src/gui/windows/charcreatedialog.cpp
@@ -45,6 +45,7 @@
#include "resources/db/chardb.h"
#include "resources/db/itemdb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -313,8 +314,7 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *const parent,
CharCreateDialog::~CharCreateDialog()
{
- delete mPlayer;
- mPlayer = nullptr;
+ delete2(mPlayer);
if (Net::getCharServerHandler())
Net::getCharServerHandler()->setCharCreateDialog(nullptr);
@@ -491,14 +491,11 @@ void CharCreateDialog::setAttributes(const StringVect &labels,
for (unsigned i = 0; i < mAttributeLabel.size(); i++)
{
remove(mAttributeLabel[i]);
- delete mAttributeLabel[i];
- mAttributeLabel[i] = nullptr;
+ delete2(mAttributeLabel[i])
remove(mAttributeSlider[i]);
- delete mAttributeSlider[i];
- mAttributeSlider[i] = nullptr;
+ delete2(mAttributeSlider[i])
remove(mAttributeValue[i]);
- delete mAttributeValue[i];
- mAttributeValue[i] = nullptr;
+ delete2(mAttributeValue[i])
}
mAttributeLabel.resize(labels.size());
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index 0a5480520..51ca414a7 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -67,6 +67,7 @@
#include "net/net.h"
#include "utils/copynpaste.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "resources/resourcemanager.h"
@@ -266,12 +267,9 @@ ChatWindow::~ChatWindow()
saveState();
config.setValue("ReturnToggles", mReturnToggles);
removeAllWhispers();
- delete mItemLinkHandler;
- mItemLinkHandler = nullptr;
- delete mColorPicker;
- mColorPicker = nullptr;
- delete mColorListModel;
- mColorListModel = nullptr;
+ delete2(mItemLinkHandler);
+ delete2(mColorPicker);
+ delete2(mColorListModel);
}
void ChatWindow::postInit()
@@ -646,8 +644,7 @@ void ChatWindow::ignoreAllWhispers()
PlayerRelation::IGNORED);
}
- delete (iter->second);
- iter->second = nullptr;
+ delete2 (iter->second)
}
}
diff --git a/src/gui/windows/debugwindow.cpp b/src/gui/windows/debugwindow.cpp
index 50dc5dbe5..438103f0a 100644
--- a/src/gui/windows/debugwindow.cpp
+++ b/src/gui/windows/debugwindow.cpp
@@ -42,6 +42,7 @@
#include "net/packetcounters.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
#include "utils/timer.h"
@@ -88,12 +89,9 @@ DebugWindow::DebugWindow() :
DebugWindow::~DebugWindow()
{
- delete mMapWidget;
- mMapWidget = nullptr;
- delete mTargetWidget;
- mTargetWidget = nullptr;
- delete mNetWidget;
- mNetWidget = nullptr;
+ delete2(mMapWidget);
+ delete2(mTargetWidget);
+ delete2(mNetWidget);
}
void DebugWindow::postInit()
diff --git a/src/gui/windows/emotewindow.cpp b/src/gui/windows/emotewindow.cpp
index 3a7141533..0f286b145 100644
--- a/src/gui/windows/emotewindow.cpp
+++ b/src/gui/windows/emotewindow.cpp
@@ -28,6 +28,7 @@
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/tabbedarea.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "resources/image.h"
@@ -121,20 +122,13 @@ EmoteWindow::~EmoteWindow()
{
mTabs->removeAll(false);
mTabs->removeTab(mTabs->getTabByIndex(0));
- delete mEmotePage;
- mEmotePage = nullptr;
- delete mColorPage;
- mColorPage = nullptr;
- delete mColorModel;
- mColorModel = nullptr;
- delete mScrollColorPage;
- mScrollColorPage = nullptr;
- delete mFontPage;
- mFontPage = nullptr;
- delete mFontModel;
- mFontModel = nullptr;
- delete mScrollFontPage;
- mScrollFontPage = nullptr;
+ delete2(mEmotePage);
+ delete2(mColorPage);
+ delete2(mColorModel);
+ delete2(mScrollColorPage);
+ delete2(mFontPage);
+ delete2(mFontModel);
+ delete2(mScrollFontPage);
if (mImageSet)
{
mImageSet->decRef();
diff --git a/src/gui/windows/equipmentwindow.cpp b/src/gui/windows/equipmentwindow.cpp
index 47e7e8b7d..4c026281b 100644
--- a/src/gui/windows/equipmentwindow.cpp
+++ b/src/gui/windows/equipmentwindow.cpp
@@ -44,6 +44,7 @@
#include "resources/imageset.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -132,14 +133,12 @@ void EquipmentWindow::postInit()
EquipmentWindow::~EquipmentWindow()
{
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
if (this == beingEquipmentWindow)
{
if (mEquipment)
delete mEquipment->getBackend();
- delete mEquipment;
- mEquipment = nullptr;
+ delete2(mEquipment)
}
delete_all(mBoxes);
mBoxes.clear();
@@ -152,8 +151,7 @@ EquipmentWindow::~EquipmentWindow()
mSlotBackground->decRef();
if (mSlotHighlightedBackground)
mSlotHighlightedBackground->decRef();
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
}
void EquipmentWindow::draw(Graphics *graphics)
diff --git a/src/gui/windows/inventorywindow.cpp b/src/gui/windows/inventorywindow.cpp
index b9bdf6ad9..c2a4b4636 100644
--- a/src/gui/windows/inventorywindow.cpp
+++ b/src/gui/windows/inventorywindow.cpp
@@ -59,6 +59,8 @@
#include "net/inventoryhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
+
#include <string>
#include "debug.h"
@@ -274,8 +276,7 @@ InventoryWindow::~InventoryWindow()
invInstances.front()->updateDropButton();
mSortDropDown->hideDrop(false);
- delete mSortModel;
- mSortModel = nullptr;
+ delete2(mSortModel);
mTextPopup = nullptr;
}
diff --git a/src/gui/windows/itemamountwindow.cpp b/src/gui/windows/itemamountwindow.cpp
index 7db944695..472057060 100644
--- a/src/gui/windows/itemamountwindow.cpp
+++ b/src/gui/windows/itemamountwindow.cpp
@@ -48,6 +48,7 @@
#include "gui/widgets/label.h"
#include "gui/widgets/slider.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -261,8 +262,7 @@ void ItemAmountWindow::postInit()
ItemAmountWindow::~ItemAmountWindow()
{
- delete mItemPopup;
- mItemPopup = nullptr;
+ delete2(mItemPopup);
}
// Show ItemTooltip
diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp
index 4db58e911..984006204 100644
--- a/src/gui/windows/logindialog.cpp
+++ b/src/gui/windows/logindialog.cpp
@@ -46,6 +46,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/paths.h"
#include "utils/process.h"
@@ -208,10 +209,8 @@ void LoginDialog::postInit()
LoginDialog::~LoginDialog()
{
- delete mUpdateTypeModel;
- mUpdateTypeModel = nullptr;
- delete mUpdateListModel;
- mUpdateListModel = nullptr;
+ delete2(mUpdateTypeModel);
+ delete2(mUpdateListModel);
}
void LoginDialog::action(const ActionEvent &event)
diff --git a/src/gui/windows/minimap.cpp b/src/gui/windows/minimap.cpp
index 583a37746..9be6d7304 100644
--- a/src/gui/windows/minimap.cpp
+++ b/src/gui/windows/minimap.cpp
@@ -39,6 +39,7 @@
#include "resources/imagehelper.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/sdlcheckutils.h"
@@ -97,8 +98,7 @@ Minimap::~Minimap()
mMapImage->decRef();
mMapImage = nullptr;
}
- delete mTextPopup;
- mTextPopup = nullptr;
+ delete2(mTextPopup);
}
void Minimap::setMap(const Map *const map)
diff --git a/src/gui/windows/ministatuswindow.cpp b/src/gui/windows/ministatuswindow.cpp
index d8f28535f..885ea619b 100644
--- a/src/gui/windows/ministatuswindow.cpp
+++ b/src/gui/windows/ministatuswindow.cpp
@@ -42,6 +42,7 @@
#include "net/playerhandler.h"
#include "net/gamehandler.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -147,10 +148,8 @@ MiniStatusWindow::MiniStatusWindow() :
MiniStatusWindow::~MiniStatusWindow()
{
- delete mTextPopup;
- mTextPopup = nullptr;
- delete mStatusPopup;
- mStatusPopup = nullptr;
+ delete2(mTextPopup);
+ delete2(mStatusPopup);
delete_all(mIcons);
mIcons.clear();
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp
index 17ff9a8c1..56306a90f 100644
--- a/src/gui/windows/npcdialog.cpp
+++ b/src/gui/windows/npcdialog.cpp
@@ -57,6 +57,7 @@
#include "net/npchandler.h"
#include "utils/copynpaste.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -216,44 +217,23 @@ NpcDialog::~NpcDialog()
delete mPlayerBox;
}
- delete mTextBox;
- mTextBox = nullptr;
- delete mClearButton;
- mClearButton = nullptr;
- delete mButton;
- mButton = nullptr;
- delete mButton2;
- mButton2 = nullptr;
- delete mButton3;
- mButton3 = nullptr;
-
- // These might not actually be in the layout, so lets be safe
- delete mScrollArea;
- mScrollArea = nullptr;
- delete mItemList;
- mItemList = nullptr;
- delete mTextField;
- mTextField = nullptr;
- delete mIntField;
- mIntField = nullptr;
- delete mResetButton;
- mResetButton = nullptr;
- delete mPlusButton;
- mPlusButton = nullptr;
- delete mMinusButton;
- mMinusButton = nullptr;
- delete mItemLinkHandler;
- mItemLinkHandler = nullptr;
-
- delete mItemContainer;
- mItemContainer = nullptr;
- delete mInventory;
- mInventory = nullptr;
- delete mItemScrollArea;
- mItemScrollArea = nullptr;
-
- delete mListScrollArea;
- mListScrollArea = nullptr;
+ delete2(mTextBox);
+ delete2(mClearButton);
+ delete2(mButton);
+ delete2(mButton2);
+ delete2(mButton3);
+ delete2(mScrollArea);
+ delete2(mItemList);
+ delete2(mTextField);
+ delete2(mIntField);
+ delete2(mResetButton);
+ delete2(mPlusButton);
+ delete2(mMinusButton);
+ delete2(mItemLinkHandler);
+ delete2(mItemContainer);
+ delete2(mInventory);
+ delete2(mItemScrollArea);
+ delete2(mListScrollArea);
FOR_EACH (ImageVectorIter, it, mImages)
{
@@ -896,8 +876,7 @@ void NpcDialog::showAvatar(const uint16_t avatarId)
}
else
{
- delete mAvatarBeing;
- mAvatarBeing = nullptr;
+ delete2(mAvatarBeing)
mPlayerBox->setPlayer(nullptr);
}
if (needShow != mShowAvatar)
diff --git a/src/gui/windows/questswindow.cpp b/src/gui/windows/questswindow.cpp
index 8d4eae9c8..b57ed9bd7 100644
--- a/src/gui/windows/questswindow.cpp
+++ b/src/gui/windows/questswindow.cpp
@@ -38,6 +38,7 @@
#include "gui/widgets/itemlinkhandler.h"
#include "gui/widgets/scrollarea.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -178,8 +179,7 @@ QuestsWindow::QuestsWindow() :
QuestsWindow::~QuestsWindow()
{
- delete mQuestsModel;
- mQuestsModel = nullptr;
+ delete2(mQuestsModel);
for (std::map<int, std::vector<QuestItem*> >::iterator it
= mQuests.begin(), it_end = mQuests.end(); it != it_end; ++ it)
@@ -194,8 +194,7 @@ QuestsWindow::~QuestsWindow()
delete_all(mAllEffects);
mAllEffects.clear();
- delete mItemLinkHandler;
- mItemLinkHandler = nullptr;
+ delete2(mItemLinkHandler);
mQuests.clear();
mQuestLinks.clear();
if (mCompleteIcon)
diff --git a/src/gui/windows/quitdialog.cpp b/src/gui/windows/quitdialog.cpp
index 560968311..5205db1e6 100644
--- a/src/gui/windows/quitdialog.cpp
+++ b/src/gui/windows/quitdialog.cpp
@@ -42,6 +42,7 @@
#include "net/gamehandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/process.h"
@@ -131,14 +132,10 @@ QuitDialog::~QuitDialog()
{
if (mMyPointer)
*mMyPointer = nullptr;
- delete mForceQuit;
- mForceQuit = nullptr;
- delete mLogoutQuit;
- mLogoutQuit = nullptr;
- delete mSwitchAccountServer;
- mSwitchAccountServer = nullptr;
- delete mSwitchCharacter;
- mSwitchCharacter = nullptr;
+ delete2(mForceQuit);
+ delete2(mLogoutQuit);
+ delete2(mSwitchAccountServer);
+ delete2(mSwitchCharacter);
}
void QuitDialog::placeOption(ContainerPlacer &placer,
diff --git a/src/gui/windows/registerdialog.cpp b/src/gui/windows/registerdialog.cpp
index 9c74cbc0d..55a328fa8 100644
--- a/src/gui/windows/registerdialog.cpp
+++ b/src/gui/windows/registerdialog.cpp
@@ -40,6 +40,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -169,8 +170,7 @@ void RegisterDialog::postInit()
RegisterDialog::~RegisterDialog()
{
- delete mWrongDataNoticeListener;
- mWrongDataNoticeListener = nullptr;
+ delete2(mWrongDataNoticeListener);
}
void RegisterDialog::action(const ActionEvent &event)
diff --git a/src/gui/windows/selldialog.cpp b/src/gui/windows/selldialog.cpp
index ebee65d1e..604caa72e 100644
--- a/src/gui/windows/selldialog.cpp
+++ b/src/gui/windows/selldialog.cpp
@@ -45,6 +45,7 @@
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -162,8 +163,7 @@ void SellDialog::init()
SellDialog::~SellDialog()
{
- delete mShopItems;
- mShopItems = nullptr;
+ delete2(mShopItems);
instances.remove(this);
}
diff --git a/src/gui/windows/serverdialog.cpp b/src/gui/windows/serverdialog.cpp
index 33b6f1599..9e85f5c89 100644
--- a/src/gui/windows/serverdialog.cpp
+++ b/src/gui/windows/serverdialog.cpp
@@ -46,6 +46,7 @@
#include "gui/widgets/listbox.h"
#include "gui/widgets/scrollarea.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/langs.h"
@@ -295,11 +296,9 @@ ServerDialog::~ServerDialog()
if (mDownload)
{
mDownload->cancel();
- delete mDownload;
- mDownload = nullptr;
+ delete2(mDownload)
}
- delete mServersListModel;
- mServersListModel = nullptr;
+ delete2(mServersListModel);
}
void ServerDialog::connectToSelectedServer()
@@ -517,8 +516,7 @@ void ServerDialog::downloadServerList()
if (mDownload)
{
mDownload->cancel();
- delete mDownload;
- mDownload = nullptr;
+ delete2(mDownload)
}
mDownload = new Net::Download(this, listFile,
diff --git a/src/gui/windows/setupwindow.cpp b/src/gui/windows/setupwindow.cpp
index 1760d00bd..7239061ff 100644
--- a/src/gui/windows/setupwindow.cpp
+++ b/src/gui/windows/setupwindow.cpp
@@ -48,6 +48,7 @@
#include "gui/widgets/label.h"
#include "gui/widgets/tabbedarea.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -223,8 +224,7 @@ void SetupWindow::unloadModTab()
mTabs.remove(mModsTab);
Tab *const tab = mPanel->getTab(mModsTab->getName());
mPanel->removeTab(tab);
- delete mModsTab;
- mModsTab = nullptr;
+ delete2(mModsTab)
}
}
diff --git a/src/gui/windows/shopwindow.cpp b/src/gui/windows/shopwindow.cpp
index 923511baa..b44dcc19e 100644
--- a/src/gui/windows/shopwindow.cpp
+++ b/src/gui/windows/shopwindow.cpp
@@ -58,6 +58,7 @@
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <sstream>
@@ -197,11 +198,8 @@ ShopWindow::~ShopWindow()
{
saveList();
- delete mBuyShopItems;
- mBuyShopItems = nullptr;
-
- delete mSellShopItems;
- mSellShopItems = nullptr;
+ delete2(mBuyShopItems);
+ delete2(mSellShopItems);
instances.remove(this);
}
diff --git a/src/gui/windows/shortcutwindow.cpp b/src/gui/windows/shortcutwindow.cpp
index 6ec442cd5..8387d7e91 100644
--- a/src/gui/windows/shortcutwindow.cpp
+++ b/src/gui/windows/shortcutwindow.cpp
@@ -30,6 +30,8 @@
#include "gui/widgets/shortcutcontainer.h"
#include "gui/widgets/tabs/tab.h"
+#include "utils/delete2.h"
+
#include "debug.h"
static const int SCROLL_PADDING = 0;
@@ -152,10 +154,8 @@ ShortcutWindow::~ShortcutWindow()
{
if (mTabs)
mTabs->removeAll();
- delete mTabs;
- mTabs = nullptr;
- delete mItems;
- mItems = nullptr;
+ delete2(mTabs);
+ delete2(mItems);
}
void ShortcutWindow::addTab(const std::string &name,
diff --git a/src/gui/windows/skilldialog.cpp b/src/gui/windows/skilldialog.cpp
index ebad47b98..f077341bf 100644
--- a/src/gui/windows/skilldialog.cpp
+++ b/src/gui/windows/skilldialog.cpp
@@ -50,6 +50,7 @@
#include "net/playerhandler.h"
#include "net/skillhandler.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -83,10 +84,8 @@ class SkillListBox final : public ListBox
~SkillListBox()
{
- delete mModel;
- mModel = nullptr;
- delete mPopup;
- mPopup = nullptr;
+ delete2(mModel)
+ delete2(mPopup)
}
SkillInfo *getSelectedInfo() const
@@ -256,8 +255,7 @@ class SkillTab final : public Tab
~SkillTab()
{
- delete mListBox;
- mListBox = nullptr;
+ delete2(mListBox)
}
SkillInfo *getSelectedInfo() const
diff --git a/src/gui/windows/socialwindow.cpp b/src/gui/windows/socialwindow.cpp
index 520184364..3f6fe663d 100644
--- a/src/gui/windows/socialwindow.cpp
+++ b/src/gui/windows/socialwindow.cpp
@@ -57,6 +57,7 @@
#include "net/guildhandler.h"
#include "net/partyhandler.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -206,10 +207,8 @@ public:
~SocialGuildTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
+ delete2(mList)
+ delete2(mScroll)
}
void action(const ActionEvent &event) override final
@@ -342,10 +341,8 @@ public:
~SocialGuildTab2()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
+ delete2(mList)
+ delete2(mScroll)
}
void action(const ActionEvent &event A_UNUSED) override final
@@ -411,10 +408,8 @@ public:
~SocialPartyTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
+ delete2(mList)
+ delete2(mScroll)
}
void action(const ActionEvent &event) override final
@@ -530,12 +525,9 @@ public:
~SocialPlayersTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -697,12 +689,9 @@ public:
~SocialNavigationTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -1026,12 +1015,9 @@ public:
~SocialAttackTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -1073,12 +1059,9 @@ public:
~SocialPickupTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -1120,12 +1103,9 @@ public:
~SocialFriendsTab()
{
- delete mList;
- mList = nullptr;
- delete mScroll;
- mScroll = nullptr;
- delete mBeings;
- mBeings = nullptr;
+ delete2(mList)
+ delete2(mScroll)
+ delete2(mBeings)
}
void updateList() override final
@@ -1371,18 +1351,12 @@ SocialWindow::~SocialWindow()
mPartyInviter.clear();
}
- delete mCreatePopup;
- mCreatePopup = nullptr;
- delete mPlayers;
- mPlayers = nullptr;
- delete mNavigation;
- mNavigation = nullptr;
- delete mAttackFilter;
- mAttackFilter = nullptr;
- delete mPickupFilter;
- mPickupFilter = nullptr;
- delete mFriends;
- mFriends = nullptr;
+ delete2(mCreatePopup);
+ delete2(mPlayers);
+ delete2(mNavigation);
+ delete2(mAttackFilter);
+ delete2(mPickupFilter);
+ delete2(mFriends);
}
bool SocialWindow::addTab(Guild *const guild)
diff --git a/src/gui/windows/statuswindow.cpp b/src/gui/windows/statuswindow.cpp
index 7fb4496cc..98d3ea82e 100644
--- a/src/gui/windows/statuswindow.cpp
+++ b/src/gui/windows/statuswindow.cpp
@@ -49,6 +49,7 @@
#include "net/playerhandler.h"
#include "net/gamehandler.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <SDL_timer.h>
@@ -791,8 +792,7 @@ AttrDisplay::AttrDisplay(const Widget2 *const widget,
AttrDisplay::~AttrDisplay()
{
- delete mLayout;
- mLayout = nullptr;
+ delete2(mLayout);
}
std::string AttrDisplay::update()
diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp
index dead469bc..2eccb255d 100644
--- a/src/gui/windows/textcommandeditor.cpp
+++ b/src/gui/windows/textcommandeditor.cpp
@@ -38,6 +38,7 @@
#include "gui/widgets/layout.h"
#include "gui/widgets/radiobutton.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -191,12 +192,9 @@ void TextCommandEditor::postInit()
TextCommandEditor::~TextCommandEditor()
{
- delete mIconsModel;
- mIconsModel = nullptr;
- delete mTargetTypeModel;
- mTargetTypeModel = nullptr;
- delete mMagicSchoolModel;
- mMagicSchoolModel = nullptr;
+ delete2(mIconsModel);
+ delete2(mTargetTypeModel);
+ delete2(mMagicSchoolModel);
}
void TextCommandEditor::action(const ActionEvent &event)
diff --git a/src/gui/windows/unregisterdialog.cpp b/src/gui/windows/unregisterdialog.cpp
index 3326ca2bb..bb309c6f1 100644
--- a/src/gui/windows/unregisterdialog.cpp
+++ b/src/gui/windows/unregisterdialog.cpp
@@ -35,6 +35,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <string>
@@ -97,8 +98,7 @@ void UnRegisterDialog::postInit()
UnRegisterDialog::~UnRegisterDialog()
{
- delete mWrongDataNoticeListener;
- mWrongDataNoticeListener = nullptr;
+ delete2(mWrongDataNoticeListener);
}
void UnRegisterDialog::action(const ActionEvent &event)
diff --git a/src/gui/windows/updaterwindow.cpp b/src/gui/windows/updaterwindow.cpp
index 70af8e7ea..cd0e7e0d8 100644
--- a/src/gui/windows/updaterwindow.cpp
+++ b/src/gui/windows/updaterwindow.cpp
@@ -42,6 +42,7 @@
#include "resources/db/moddb.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "utils/mkdir.h"
#include "utils/paths.h"
@@ -242,8 +243,7 @@ UpdaterWindow::~UpdaterWindow()
{
mDownload->cancel();
- delete mDownload;
- mDownload = nullptr;
+ delete2(mDownload)
}
free(mMemoryBuffer);
}
diff --git a/src/gui/windows/worldselectdialog.cpp b/src/gui/windows/worldselectdialog.cpp
index 963da8f22..5cd0a3b2f 100644
--- a/src/gui/windows/worldselectdialog.cpp
+++ b/src/gui/windows/worldselectdialog.cpp
@@ -38,6 +38,7 @@
#include "net/loginhandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -95,8 +96,7 @@ void WorldSelectDialog::postInit()
WorldSelectDialog::~WorldSelectDialog()
{
- delete mWorldListModel;
- mWorldListModel = nullptr;
+ delete2(mWorldListModel);
}
void WorldSelectDialog::action(const ActionEvent &event)
diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp
index a1fab3b1e..48485e9b4 100644
--- a/src/guildmanager.cpp
+++ b/src/guildmanager.cpp
@@ -36,6 +36,7 @@
#include "net/chathandler.h"
#include "net/net.h"
+#include "utils/delete2.h"
#include "utils/timer.h"
#include "debug.h"
@@ -60,8 +61,7 @@ GuildManager::GuildManager() :
GuildManager::~GuildManager()
{
- delete mTab;
- mTab = nullptr;
+ delete2(mTab);
}
void GuildManager::init()
@@ -85,8 +85,7 @@ void GuildManager::init()
}
else if (guildManager)
{
- delete guildManager;
- guildManager = nullptr;
+ delete2(guildManager);
}
}
@@ -108,8 +107,7 @@ void GuildManager::reload()
if (guild && socialWindow)
socialWindow->removeTab(guild);
}
- delete mTab;
- mTab = nullptr;
+ delete2(mTab);
}
void GuildManager::send(const std::string &msg)
@@ -520,8 +518,7 @@ bool GuildManager::afterRemove()
player_node->clearGuilds();
}
NotifyManager::notify(NotifyManager::GUILD_LEFT);
- delete mTab;
- mTab = nullptr;
+ delete2(mTab);
if (socialWindow)
socialWindow->removeTab(guild);
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 90fd1c94a..6213b44c9 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -30,6 +30,7 @@
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include <algorithm>
@@ -153,8 +154,7 @@ void Inventory::removeItem(const int id)
void Inventory::removeItemAt(const int index)
{
- delete mItems[index];
- mItems[index] = nullptr;
+ delete2(mItems[index]);
mUsed--;
if (mUsed < 0) // Already at 0, no need to distribute event
mUsed = 0;
diff --git a/src/main.cpp b/src/main.cpp
index 75305233f..35a5570ea 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -29,6 +29,7 @@
#include <iostream>
#include <unistd.h>
+#include "utils/delete2.h"
#include "utils/gettext.h"
#ifdef ANDROID
#include "utils/mkdir.h"
@@ -320,8 +321,7 @@ int main(int argc, char *argv[])
client->testsInit();
ret = client->testsExec();
}
- delete client;
- client = nullptr;
+ delete2(client);
#if SDL_MIXER_VERSION_ATLEAST(1, 2, 11)
Mix_Quit();
diff --git a/src/map.cpp b/src/map.cpp
index c86c51bce..b4112231d 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -42,6 +42,7 @@
#include "resources/resourcemanager.h"
#include "resources/subimage.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/mkdir.h"
#include "utils/physfstools.h"
@@ -98,8 +99,7 @@ TileAnimation::TileAnimation(Animation *const ani):
TileAnimation::~TileAnimation()
{
- delete mAnimation;
- mAnimation = nullptr;
+ delete2(mAnimation);
}
bool TileAnimation::update(const int ticks)
@@ -202,7 +202,6 @@ Map::~Map()
config.removeListeners(this);
CHECKLISTENERS
- // delete metadata, layers, tilesets and overlays
delete [] mMetaTiles;
for (int i = 0; i < NB_BLOCKTYPES; i++)
delete [] mOccupation[i];
@@ -218,20 +217,16 @@ Map::~Map()
delete_all(mForegrounds);
delete_all(mBackgrounds);
delete_all(mTileAnimations);
- delete mSpecialLayer;
- mSpecialLayer = nullptr;
- delete mTempLayer;
- mTempLayer = nullptr;
- delete mObjects;
- mObjects = nullptr;
+ delete2(mSpecialLayer);
+ delete2(mTempLayer);
+ delete2(mObjects);
delete_all(mMapPortals);
if (mAtlas)
{
mAtlas->decRef();
mAtlas = nullptr;
}
- delete mHeights;
- mHeights = nullptr;
+ delete2(mHeights);
}
void Map::optionChanged(const std::string &value)
diff --git a/src/maplayer.cpp b/src/maplayer.cpp
index 701fa9958..2db140d67 100644
--- a/src/maplayer.cpp
+++ b/src/maplayer.cpp
@@ -39,6 +39,7 @@
#include "gui/font.h"
#include "gui/gui.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "debug.h"
@@ -586,10 +587,7 @@ SpecialLayer::SpecialLayer(const int width, const int height) :
SpecialLayer::~SpecialLayer()
{
for (int f = 0; f < mWidth * mHeight; f ++)
- {
- delete mTiles[f];
- mTiles[f] = nullptr;
- }
+ delete2(mTiles[f])
delete [] mTiles;
}
diff --git a/src/net/charserverhandler.h b/src/net/charserverhandler.h
index 625bf57fc..095558cec 100644
--- a/src/net/charserverhandler.h
+++ b/src/net/charserverhandler.h
@@ -26,6 +26,8 @@
#include "being/localplayer.h"
#include "being/playerinfo.h"
+#include "utils/delete2.h"
+
#include <string>
#include <vector>
@@ -51,8 +53,7 @@ struct Character final
~Character()
{
- delete dummy;
- dummy = nullptr;
+ delete2(dummy);
}
int slot; /**< The index in the list of characters */
diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp
index 1e56ac75b..fc1ef8def 100644
--- a/src/net/ea/guildhandler.cpp
+++ b/src/net/ea/guildhandler.cpp
@@ -34,6 +34,8 @@
#include "net/ea/gui/guildtab.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace Ea
@@ -48,8 +50,7 @@ GuildHandler::GuildHandler() :
GuildHandler::~GuildHandler()
{
- delete guildTab;
- guildTab = nullptr;
+ delete2(guildTab);
}
void GuildHandler::requestAlliance(const int guildId A_UNUSED,
@@ -462,8 +463,7 @@ void GuildHandler::processGuildLeave(Net::MessageIn &msg) const
taGuild->clearMembers();
}
NotifyManager::notify(NotifyManager::GUILD_LEFT);
- delete guildTab;
- guildTab = nullptr;
+ delete2(guildTab)
if (socialWindow && taGuild)
socialWindow->removeTab(taGuild);
@@ -506,8 +506,7 @@ void GuildHandler::processGuildExpulsion(Net::MessageIn &msg) const
taGuild->clearMembers();
}
NotifyManager::notify(NotifyManager::GUILD_KICKED);
- delete guildTab;
- guildTab = nullptr;
+ delete2(guildTab)
if (socialWindow && taGuild)
socialWindow->removeTab(taGuild);
diff --git a/src/net/ea/inventoryhandler.cpp b/src/net/ea/inventoryhandler.cpp
index 2262a79f9..f3c8040e1 100644
--- a/src/net/ea/inventoryhandler.cpp
+++ b/src/net/ea/inventoryhandler.cpp
@@ -33,6 +33,8 @@
#include "net/ea/eaprotocol.h"
+#include "utils/delete2.h"
+
#include "debug.h"
extern int serverVersion;
@@ -95,14 +97,12 @@ InventoryHandler::~InventoryHandler()
mStorageWindow = nullptr;
}
- delete mStorage;
- mStorage = nullptr;
+ delete2(mStorage);
}
void InventoryHandler::clear()
{
- delete mStorage;
- mStorage = nullptr;
+ delete2(mStorage);
}
bool InventoryHandler::canSplit(const Item *const item A_UNUSED) const
@@ -491,8 +491,7 @@ void InventoryHandler::processPlayerStorageClose(Net::MessageIn &msg A_UNUSED)
if (mStorage)
mStorage->clear();
- delete mStorage;
- mStorage = nullptr;
+ delete2(mStorage);
}
void InventoryHandler::processPlayerEquipment(Net::MessageIn &msg)
diff --git a/src/net/ea/partyhandler.cpp b/src/net/ea/partyhandler.cpp
index 4e4cac3df..32b08046e 100644
--- a/src/net/ea/partyhandler.cpp
+++ b/src/net/ea/partyhandler.cpp
@@ -35,6 +35,8 @@
#include "net/ea/gui/partytab.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace Ea
@@ -52,8 +54,7 @@ PartyHandler::PartyHandler() :
PartyHandler::~PartyHandler()
{
- delete partyTab;
- partyTab = nullptr;
+ delete2(partyTab);
}
void PartyHandler::join(const int partyId A_UNUSED) const
@@ -347,8 +348,7 @@ void PartyHandler::processPartyLeave(Net::MessageIn &msg) const
Ea::taParty->clearMembers();
}
NotifyManager::notify(NotifyManager::PARTY_LEFT);
- delete Ea::partyTab;
- Ea::partyTab = nullptr;
+ delete2(Ea::partyTab)
if (socialWindow && Ea::taParty)
socialWindow->removeTab(Ea::taParty);
diff --git a/src/net/eathena/generalhandler.cpp b/src/net/eathena/generalhandler.cpp
index 3a18dede9..6243a3878 100644
--- a/src/net/eathena/generalhandler.cpp
+++ b/src/net/eathena/generalhandler.cpp
@@ -54,6 +54,7 @@
#include "net/eathena/tradehandler.h"
#include "net/eathena/skillhandler.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -105,8 +106,7 @@ GeneralHandler::GeneralHandler() :
GeneralHandler::~GeneralHandler()
{
- delete mNetwork;
- mNetwork = nullptr;
+ delete2(mNetwork);
}
void GeneralHandler::handleMessage(Net::MessageIn &msg)
@@ -272,11 +272,8 @@ void GeneralHandler::gameEnded() const
socialWindow->removeTab(Ea::taParty);
}
- delete Ea::guildTab;
- Ea::guildTab = nullptr;
-
- delete Ea::partyTab;
- Ea::partyTab = nullptr;
+ delete2(Ea::guildTab);
+ delete2(Ea::partyTab);
}
} // namespace EAthena
diff --git a/src/net/eathena/network.cpp b/src/net/eathena/network.cpp
index 0162d82e8..87d5d4b5a 100644
--- a/src/net/eathena/network.cpp
+++ b/src/net/eathena/network.cpp
@@ -28,6 +28,8 @@
#include "net/eathena/messagein.h"
#include "net/eathena/protocol.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace EAthena
@@ -120,8 +122,7 @@ Network::Network() :
Network::~Network()
{
clearHandlers();
- delete mMessageHandlers;
- mMessageHandlers = nullptr;
+ delete2(mMessageHandlers);
mInstance = nullptr;
}
diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp
index 46d1d490f..3848fcdd6 100644
--- a/src/net/tmwa/generalhandler.cpp
+++ b/src/net/tmwa/generalhandler.cpp
@@ -56,6 +56,7 @@
#include "net/tmwa/skillhandler.h"
#include "net/tmwa/questhandler.h"
+#include "utils/delete2.h"
#include "utils/gettext.h"
#include "debug.h"
@@ -115,8 +116,7 @@ GeneralHandler::GeneralHandler() :
GeneralHandler::~GeneralHandler()
{
- delete mNetwork;
- mNetwork = nullptr;
+ delete2(mNetwork);
}
void GeneralHandler::handleMessage(Net::MessageIn &msg)
@@ -320,11 +320,8 @@ void GeneralHandler::gameEnded() const
socialWindow->removeTab(Ea::taParty);
}
- delete Ea::guildTab;
- Ea::guildTab = nullptr;
-
- delete Ea::partyTab;
- Ea::partyTab = nullptr;
+ delete2(Ea::guildTab);
+ delete2(Ea::partyTab);
}
} // namespace TmwAthena
diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp
index cc94b6161..b778d6b31 100644
--- a/src/net/tmwa/network.cpp
+++ b/src/net/tmwa/network.cpp
@@ -28,6 +28,8 @@
#include "net/tmwa/messagein.h"
#include "net/tmwa/protocol.h"
+#include "utils/delete2.h"
+
#include "debug.h"
namespace TmwAthena
@@ -98,8 +100,7 @@ Network::Network() :
Network::~Network()
{
clearHandlers();
- delete mMessageHandlers;
- mMessageHandlers = nullptr;
+ delete2(mMessageHandlers);
mInstance = nullptr;
}
diff --git a/src/particle/animationparticle.cpp b/src/particle/animationparticle.cpp
index 4381ceb8a..dccd3d037 100644
--- a/src/particle/animationparticle.cpp
+++ b/src/particle/animationparticle.cpp
@@ -24,6 +24,8 @@
#include "simpleanimation.h"
+#include "utils/delete2.h"
+
#include "debug.h"
AnimationParticle::AnimationParticle(Animation *const animation) :
@@ -41,8 +43,7 @@ AnimationParticle::AnimationParticle(XmlNodePtrConst animationNode,
AnimationParticle::~AnimationParticle()
{
- delete mAnimation;
- mAnimation = nullptr;
+ delete2(mAnimation);
mImage = nullptr;
}
diff --git a/src/particle/particlecontainer.cpp b/src/particle/particlecontainer.cpp
index 0c73d2762..07eb36dc4 100644
--- a/src/particle/particlecontainer.cpp
+++ b/src/particle/particlecontainer.cpp
@@ -23,6 +23,8 @@
#include "particle/particle.h"
#include "particle/particlecontainer.h"
+#include "utils/delete2.h"
+
#include "debug.h"
typedef std::list<Particle *>::iterator ParticleListIter;
@@ -40,10 +42,7 @@ ParticleContainer::~ParticleContainer()
// +++ call virtul method in destructor
clearLocally();
if (mDelParent)
- {
- delete mNext;
- mNext = nullptr;
- }
+ delete2(mNext)
}
void ParticleContainer::clear()
diff --git a/src/particle/rotationalparticle.cpp b/src/particle/rotationalparticle.cpp
index 2a1fe7904..976234f83 100644
--- a/src/particle/rotationalparticle.cpp
+++ b/src/particle/rotationalparticle.cpp
@@ -24,6 +24,8 @@
#include "simpleanimation.h"
+#include "utils/delete2.h"
+
#include <cmath>
#include "debug.h"
@@ -46,8 +48,7 @@ RotationalParticle::RotationalParticle(const XmlNodePtr animationNode,
RotationalParticle::~RotationalParticle()
{
- delete mAnimation;
- mAnimation = nullptr;
+ delete2(mAnimation);
mImage = nullptr;
}
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index 40ea7af1a..8b76d7e2a 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -25,6 +25,7 @@
#include "configuration.h"
#include "logger.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -168,10 +169,8 @@ void BeingInfo::addAttack(const int id, std::string action,
void BeingInfo::clear()
{
- delete unknown;
- unknown = nullptr;
- delete empty;
- empty = nullptr;
+ delete2(unknown);
+ delete2(empty);
}
void BeingInfo::init()
diff --git a/src/resources/db/itemdb.cpp b/src/resources/db/itemdb.cpp
index 931377639..09a5ce08f 100644
--- a/src/resources/db/itemdb.cpp
+++ b/src/resources/db/itemdb.cpp
@@ -28,6 +28,7 @@
#include "resources/beingcommon.h"
#include "resources/iteminfo.h"
+#include "utils/delete2.h"
#include "utils/dtor.h"
#include "utils/gettext.h"
@@ -543,8 +544,7 @@ void ItemDB::unload()
{
logger->log1("Unloading item database...");
- delete mUnknown;
- mUnknown = nullptr;
+ delete2(mUnknown);
delete_all(mItemInfos);
mItemInfos.clear();
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 4f9e8a738..7e6692c50 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -26,6 +26,8 @@
#include "resources/db/palettedb.h"
+#include "utils/delete2.h"
+
#include <cmath>
#include <sstream>
@@ -442,10 +444,7 @@ Dye::Dye(const std::string &description)
Dye::~Dye()
{
for (int i = 0; i < dyePalateSize; ++i)
- {
- delete mDyePalettes[i];
- mDyePalettes[i] = nullptr;
- }
+ delete2(mDyePalettes[i])
}
void Dye::instantiate(std::string &restrict target,
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 6d7591d1d..baabbeaec 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -37,6 +37,7 @@
#include "resources/db/mapdb.h"
#include "utils/base64.h"
+#include "utils/delete2.h"
#include <iostream>
#include <zlib.h>
@@ -977,14 +978,9 @@ Tileset *MapReader::readTileset(XmlNodePtr node,
}
if (ani->getLength() > 0)
- {
map->addAnimation(tileGID, new TileAnimation(ani));
- }
else
- {
- delete ani;
- ani = nullptr;
- }
+ delete2(ani)
}
}
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 954930b64..4eca5552e 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -37,6 +37,7 @@
#include "resources/soundeffect.h"
#include "resources/spritedef.h"
+#include "utils/delete2.h"
#include "utils/mkdir.h"
#include "utils/paths.h"
#include "utils/physfscheckutils.h"
@@ -953,8 +954,7 @@ void ResourceManager::deleteInstance()
}
}
#endif
- delete instance;
- instance = nullptr;
+ delete2(instance);
}
void *ResourceManager::loadFile(const std::string &fileName, int &fileSize)
diff --git a/src/shopitem.cpp b/src/shopitem.cpp
index 8ee8da670..45ab60e05 100644
--- a/src/shopitem.cpp
+++ b/src/shopitem.cpp
@@ -138,7 +138,6 @@ int ShopItem::sellCurrentDuplicate(const int quantity)
if (dupl->quantity == 0)
{
delete dupl;
- dupl = nullptr;
mDuplicates.pop();
}
return sellCount;
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 075c98c06..a2c765cb8 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -32,6 +32,8 @@
#include "resources/imageset.h"
#include "resources/resourcemanager.h"
+#include "utils/delete2.h"
+
#include "debug.h"
SimpleAnimation::SimpleAnimation(Animation *const animation) :
@@ -62,8 +64,7 @@ SimpleAnimation::SimpleAnimation(const XmlNodePtr animationNode,
SimpleAnimation::~SimpleAnimation()
{
- delete mAnimation;
- mAnimation = nullptr;
+ delete2(mAnimation);
if (mImageSet)
{
mImageSet->decRef();
diff --git a/src/test/testmain.cpp b/src/test/testmain.cpp
index fadeb206e..fbd7588ef 100644
--- a/src/test/testmain.cpp
+++ b/src/test/testmain.cpp
@@ -25,6 +25,7 @@
#include "client.h"
+#include "utils/delete2.h"
#include "utils/paths.h"
#include "utils/process.h"
@@ -46,8 +47,7 @@ TestMain::TestMain() :
TestMain::~TestMain()
{
- delete log;
- log = nullptr;
+ delete2(log);
}
void TestMain::initConfig()
diff --git a/src/text.cpp b/src/text.cpp
index bf75e80d6..542dc60d9 100644
--- a/src/text.cpp
+++ b/src/text.cpp
@@ -32,6 +32,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
int Text::mInstances = 0;
@@ -99,8 +101,7 @@ Text::~Text()
textManager->removeText(this);
if (--mInstances == 0)
{
- delete textManager;
- textManager = nullptr;
+ delete2(textManager);
for (int f = 0; f < 9; f ++)
{
if (mBubble.grid[f])
diff --git a/src/touchmanager.cpp b/src/touchmanager.cpp
index 58aee1d3b..d1c29999c 100644
--- a/src/touchmanager.cpp
+++ b/src/touchmanager.cpp
@@ -37,6 +37,8 @@
#include "resources/image.h"
+#include "utils/delete2.h"
+
#include "debug.h"
TouchManager touchManager;
@@ -70,8 +72,7 @@ TouchManager::TouchManager() :
TouchManager::~TouchManager()
{
clear();
- delete mVertexes;
- mVertexes = nullptr;
+ delete2(mVertexes);
CHECKLISTENERS
}
@@ -357,8 +358,7 @@ void TouchManager::unload(TouchItem *const item)
if (item->images)
{
Theme::unloadRect(*item->images);
- delete item->images;
- item->images = nullptr;
+ delete2(item->images);
if (item->icon)
{
item->icon->decRef();
diff --git a/src/utils/delete2.h b/src/utils/delete2.h
new file mode 100644
index 000000000..104f6fa60
--- /dev/null
+++ b/src/utils/delete2.h
@@ -0,0 +1,30 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef UTILS_DELETE2_H
+#define UTILS_DELETE2_H
+
+#define delete2(var) \
+ {\
+ delete var;\
+ var = nullptr;\
+ }
+
+#endif // UTILS_DELETE2_H
diff --git a/src/utils/translation/translationmanager.cpp b/src/utils/translation/translationmanager.cpp
index 893e4d33f..9bbdec810 100644
--- a/src/utils/translation/translationmanager.cpp
+++ b/src/utils/translation/translationmanager.cpp
@@ -20,6 +20,7 @@
#include "utils/translation/translationmanager.h"
+#include "utils/delete2.h"
#include "utils/stringutils.h"
#include "utils/translation/podict.h"
@@ -46,8 +47,7 @@ void TranslationManager::loadCurrentLang()
void TranslationManager::close()
{
- delete translator;
- translator = nullptr;
+ delete2(translator);
}
PoDict *TranslationManager::loadLang(const LangVect &lang,