1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Possible crash while razing cities in trunk

Discussion in 'Civ4 - Better AI' started by Terkhen, Sep 21, 2011.

  1. Terkhen

    Terkhen King

    Aug 1, 2011
    United Kingdom
    While debugging a crash in Realism Invictus SVN, I found that it was caused by Better BtS AI.

    RI stacktrace:

    CvGameCoreDLL.dll!CvWString::CvWString()  + 0x46 Bytes   C++
    CvGameCoreDLL.dll!CvCity::getName()  + 0x26 Bytes   C++
    CvGameCoreDLL.dll!CvPlayerAI::AI_conquerCity()  + 0xa19 Bytes   C++
    CvGameCoreDLL.dll!CvGame::isOption()  + 0x16 Bytes   C++
    CvGameCoreDLL.dll!CvPlayer::acquireCity()  + 0x191b Bytes   C++
    CvGameCoreDLL.dll!CvUnit::setXY()  + 0xab6 Bytes   C++
    CvGameCoreDLL.dll!CvUnit::move()  + 0xdc Bytes   C++
    CvGameCoreDLL.dll!CvSelectionGroup::groupMove()  + 0xff Bytes   C++
    CvGameCoreDLL.dll!CvUnit::updateCombat()  + 0x106d Bytes   C++
    CvGameCoreDLL.dll!CvUnit::attack()  + 0x16 Bytes   C++
    CvGameCoreDLL.dll!CvSelectionGroup::groupAttack()  + 0x3dd Bytes   C++
    CvGameCoreDLL.dll!__wcsicmp()  + 0x44c66 Bytes   C++
    CvGameCoreDLL.dll!FFreeListTrashArray<CvUnitAI>::getAt()  + 0x37 Bytes   C++
    CvGameCoreDLL.dll!CvUnit::isCombat()  + 0x16 Bytes   C++
    CvGameCoreDLL.dll!CvSelectionGroup::isBusy()  + 0x3e Bytes   C++
    CvGameCoreDLL.dll!CvSelectionGroup::startMission()  + 0x7b2 Bytes   C++
    CvGameCoreDLL.dll!CvSelectionGroup::insertAtEndMissionQueue()  + 0x35 Bytes   C++
    CvGameCoreDLL.dll!CvSelectionGroup::pushMission()  + 0x10d Bytes   C++
    CvGameCoreDLL.dll!CvUnitAI::AI_cityAttack()  + 0x25a Bytes   C++
    CvGameCoreDLL.dll!CvUnitAI::AI_attackMove()  + 0x4fa Bytes   C++
    CvGameCoreDLL.dll!CvUnitAI::AI_update()  + 0x4ac Bytes   C++
    CvGameCoreDLL.dll!CvSelectionGroupAI::AI_update()  + 0x1ea Bytes   C++
    CvGameCoreDLL.dll!CvPlayerAI::AI_unitUpdate()  + 0x27a Bytes   C++
    CvGameCoreDLL.dll!CvGame::updateMoves()  + 0x95 Bytes   C++
    CvGameCoreDLL.dll!CvGame::update()  + 0x360 Bytes   C++
    I found out that the code causing it are these lines in CvPlayerAI.cpp (starting at line 1930 of http://civ4betterai.svn.sourceforge...reDLL/CvPlayerAI.cpp?revision=597&view=markup):

    if( bRaze )
       logBBAI("    Player %d (%S) decides to to raze city %S!!!", getID(), getCivilizationDescription(0), pCity->getName().GetCString() );
    As you can see, logBBAI tries to access pCity->getName(). pCity is already deleted; the previous line removes it from the memory after a lot of operations. Therefore, the game crashes in getName() since pCity does not exist anymore. Inverting both lines did the trick for Realism Invictus.

    I was not able to test if this crash happens in vanilla Better BtS AI because I could not figure out how to build it with the sln project included in the svn repository, but since that part of the code seems like a unmodified copy I'm guessing that it does, and maybe you want to check it.
  2. Axios

    Axios Warlord

    Oct 19, 2009
    Hi, the crash occour when you raze a city or when a AI raze a city?

    I have vanilla BBAI 1.02 and never experienced a crash when I raze a city or AI do it.

    However BBAI developement is ceased. Jdog stop the development for personal reasons. Try to Fuyu's Better BUG Ai....
  3. Terkhen

    Terkhen King

    Aug 1, 2011
    United Kingdom
    Thank you for the pointer!

    It seems that Fuyu's better BUG AI already includes this fix. I'll check its revision log more thoroughly, maybe it makes sense to import more fixes and improvements to RI. I would have prefered to check it as separate code, though.

Share This Page