From 7a65eb17a322cb22e7940504797844114fb77d79 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 07:54:38 -0700 Subject: Fix some problems with deleting NPCs early --- src/beingmanager.cpp | 11 ++++++++++- src/net/npchandler.cpp | 2 +- src/npc.cpp | 12 +++--------- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 3c8edf86..3b73d29f 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -96,7 +96,10 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) void BeingManager::destroyBeing(Being *being) { mBeings.remove(being); - delete being; + if (being == current_npc) + current_npc->handleDeath(); + else + delete being; } Being* BeingManager::findBeing(Uint32 id) @@ -193,6 +196,12 @@ void BeingManager::clear() mBeings.remove(player_node); } + if (current_npc) + { + mBeings.remove(current_npc); + current_npc->handleDeath(); + } + delete_all(mBeings); mBeings.clear(); diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 5ae2ac2e..ae521bd5 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -94,7 +94,7 @@ void NPCHandler::handleMessage(MessageIn *msg) // If we're talking to that NPC, show the next button if (temporaryNPC == current_npc) npcTextDialog->showNextButton(); - else + else if (temporaryNPC) // Otherwise, move on as an empty dialog doesn't help temporaryNPC->nextDialog(); break; diff --git a/src/npc.cpp b/src/npc.cpp index 701e280b..658334bc 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -75,12 +75,6 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): NPC::~NPC() { - if (current_npc == this) // Don't delete if current NPC - { - handleDeath(); - return; - } - delete mName; } @@ -112,7 +106,7 @@ Being::Type NPC::getType() const void NPC::talk() { - if (!mNetwork) return; + if (!this || !mNetwork) return; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_TALK); outMsg.writeInt32(mId); @@ -121,7 +115,7 @@ void NPC::talk() void NPC::nextDialog() { - if (!mNetwork) return; + if (!this || !mNetwork) return; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); outMsg.writeInt32(mId); @@ -187,7 +181,7 @@ void NPC::handleDeath() if (npcTextDialog->isVisible()) npcTextDialog->showCloseButton(); - else { + else if (current_npc) { NPC *temp = current_npc; current_npc = NULL; delete temp; -- cgit v1.2.3-70-g09d2