Crash with ranged bombard

NotSoGood

Emperor
Joined
Jan 25, 2009
Messages
1,077
Location
Finland
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:
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));
						}
...
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?
 
Could the whole problem be caused by GetBestDefender returning a NULL value when it can't find a valid defender? You need to have a check for that before using pDefender.
 
Great, so far no asserts. I played a small few 100 turns test game and it seemed to work well. I'll have to test some more to see if it changed something in the code which I don't think. Thank you. :goodjob:
 
Top Bottom