Jump to content

Need Help: Destuctor Crash


pasdVn

Recommended Posts

Hey guys,

need the help of one of you pros one more time ;-) It is probably more a generic programming problem. That is why I post it here.

Following szenario: I want to access the class PetAI from an extern scripting project (to be more specific: scriptdev2). I use the following code (just a minimal example):

/* Copyright (C) 2006 - 2010 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* 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
* (at your option) 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

/* ScriptData
SDName: Pet_Scripts
SD%Complete: ??
SDComment: Here is the place for scripted AI for guardian and mini pets.
SDCategory: Pets
EndScriptData */

#include "precompiled.h"
#include "PetAI.h"

struct MANGOS_DLL_DECL pet_simple_guardianAI : public PetAI
{
   pet_simple_guardianAI(Creature* pCreature): PetAI(pCreature)
   {
   }
};


CreatureAI* GetAI_pet_simple_guardian(Creature* pCreature)
{
   if (pCreature->isPet())
       return new pet_simple_guardianAI(pCreature);
   else
       return NULL;
}

void AddSC_pets()
{
   Script *newscript;

   newscript = new Script;
   newscript->Name = "pet_simple_guardian";
   newscript->GetAI = &GetAI_pet_simple_guardian;
   newscript->RegisterSelf();
}

I ofc also added the declaration and call in ScriptLoader.cpp and defined PetAI as MANGOS_DLL_SPEC to get acess from the extern dll.

The Problem: Code compiles and works until the pet (guardian pet) get's delete (and thus the AI). I always a get a crash at the destructor which I can not really understand.

> msvcr90d.dll!operator delete(void * pUserData=0x6eaebee0) Line 52 + 0x51 bytes C++

mangosscript.dll!std::allocator<std::_Tree_nod<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::_Node>::Deallocate(std::_Tree_nod<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::_Node * _Ptr=0x6eaebee0, unsigned int __formal=1) Line 140 + 0x9 bytes C++

mangosscript.dll!std::_Tree<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::_Erase(std::_Tree_nod<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::_Node * _Rootnode=0x6eaebee0) Line 1173 C++

mangosscript.dll!std::_Tree<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::clear() Line 972 C++

mangosscript.dll!std::_Tree<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::erase(std::_Tree<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::const_iterator _First=27, std::_Tree<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::const_iterator _Last=1065353216) Line 938 C++

mangosscript.dll!std::_Tree<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::_Tidy() Line 1421 + 0xaa bytes C++

mangosscript.dll!std::_Tree<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >::~_Tree<std::_Tset_traits<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64>,0> >() Line 541 C++

mangosscript.dll!std::set<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64> >::~set<unsigned __int64,std::less<unsigned __int64>,std::allocator<unsigned __int64> >() + 0x2b bytes C++

mangosscript.dll!PetAI::~PetAI() + 0x54 bytes C++

mangosscript.dll!pet_simple_guardianAI::~pet_simple_guardianAI() + 0x2b bytes C++

mangosscript.dll!pet_simple_guardianAI::`scalar deleting destructor'() + 0x2b bytes C++

mangosd.exe!Creature::~Creature() Line 149 + 0x28 bytes C++

mangosd.exe!Pet::~Pet() Line 59 + 0x45 bytes C++

mangosd.exe!Pet::`scalar deleting destructor'() + 0x16 bytes C++

mangosd.exe!Map::DeleteFromWorld<Creature>(Creature * obj=0x6e8a4000) Line 248 + 0x22 bytes C++

mangosd.exe!Map::Remove<Creature>(Creature * obj=0x6e8a4000, bool remove=true) Line 733 C++

mangosd.exe!Map::RemoveAllObjectsInRemoveList() Line 1521 C++

mangosd.exe!MapManager::RemoveAllObjectsInRemoveList() Line 276 + 0x1d bytes C++

mangosd.exe!World::Update(unsigned int diff=141) Line 1553 C++

mangosd.exe!WorldRunnable::run() Line 61 C++

mangosd.exe!ACE_Based::Thread::ThreadTask(void * param=0x72085900) Line 187 + 0xf bytes C++

ACEd.dll!ACE_OS_Thread_Adapter::invoke() Line 90 + 0x9 bytes C++

ACEd.dll!ace_thread_adapter(void * args=0x0bc319d8) Line 124 + 0xf bytes C++

msvcr90d.dll!_callthreadstartex() Line 348 + 0xf bytes C

msvcr90d.dll!_threadstartex(void * ptd=0x0bc35988) Line 331 C

kernel32.dll!76751194()

[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]

ntdll.dll!77cab495()

ntdll.dll!77cab468()

I guess, that is somehow to do with the dll export (I do not really understand that much of those things) as the code runs _without_ problems at linux.

I already tried various things, as definig the destructor explicit in PetAI/ pet_simple_guardianAI, make it virtual (althoug it anway only is called via CreatureAI pointers), using a class instead of a struct etc.

Did not have success until now. Always the same crash.

Hope anybody of you can give me a hint.

Greetings pasdVn

Edit: Omg. Finally I got it work! I defined an empty destructor for petAI, but not in the header, but in the cpp file. Probably he had problems, when calling the default destructor of a mangos-own function (bt: mangosscript.dll!PetAI::~PetAI() + 0x54 bytes C++ ).

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use