Could someone help me with this assert I got? It has been long since I've changed the code and haven't notice anything wrong, until today. I was running a debug dll/VC++ attached test, when it suddenly popped up an assert failure (first screenshot). It stopped here:
I used VC's ability to check pDefender's value, but it doesn't seem to have a proper value (second screenshot). So the line before the assert is the only place where it's been defined and for some reason it returns something odd.
Does anyone have ideas how to start hunting down the error?
Spoiler :
Code:
...
if(GC.getDCM_RANGE_BOMBARD())
{
iSearchRange = getDCMBombRange();
iBestValue = 0;
pBestPlot = NULL;
for (iDX = -(iSearchRange); iDX <= iSearchRange; iDX++)
{
for (iDY = -(iSearchRange); iDY <= iSearchRange; iDY++)
{
pLoopPlot = plotXY(getX_INLINE(), getY_INLINE(), iDX, iDY);
if (pLoopPlot != NULL)
{
if (canBombardAtRanged(plot(), pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE()))
{
iValue = 0;
pCity = pLoopPlot->getPlotCity();
if (pCity != NULL)
{
iValue += std::max(0, (std::min((pCity->getDefenseDamage() + airBombCurrRate()), GC.getMAX_CITY_DEFENSE_DAMAGE()) - pCity->getDefenseDamage()));
iValue *= 5;
if (pCity->AI_isDanger())
{
iValue *= 2;
}
if (pCity == pCity->area()->getTargetCity(getOwnerINLINE()))
{
iValue *= 3;
}
}
iPotentialAttackers = GET_PLAYER(getOwnerINLINE()).AI_adjacentPotentialAttackers(pLoopPlot);//pLoopPlot->getNumVisibleEnemyDefenders(NO_PLAYER);
if (iPotentialAttackers > 0 || pLoopPlot->isAdjacentTeam(getTeam()))
{
pDefender = pLoopPlot->getBestDefender(NO_PLAYER, getOwnerINLINE(), this, true);
[COLOR="Red"]FAssert(pDefender != NULL);[/COLOR]
FAssert(pDefender->canDefend());
iDamage = GC.getGameINLINE().getSorenRandNum(bombardRate(), "AI Bombard");
// iValue = max(0, (min((pDefender->getDamage() + iDamage), bombardRate()) - pDefender->getDamage()));
iValue += ((((iDamage * collateralDamage()) / 100) * std::min((pLoopPlot->getNumVisibleEnemyDefenders(this) - 1), collateralDamageMaxUnits())) / 2);
iValue *= (3 + iPotentialAttackers);
iValue /= 4;
}
iValue *= GC.getGameINLINE().getSorenRandNum(20, "AI Bombard");
if (iValue > iBestValue)
{
iBestValue = iValue;
pBestPlot = pLoopPlot;
FAssert(!atPlot(pBestPlot));
}
...
Does anyone have ideas how to start hunting down the error?