j_mie6
Deity
can anybody we what is wrong with this code in that it causes a crash, consistently, the third time a plot is accessed (where the function is called on every plot in the game via a for loop on getPlotByIndex()) in which that plot has an improvement other than NO_IMPROVEMENT.
Here's the code:
where the getVisibilityRadius is just an extra field in the improvement infos. Bold represents possible area of crash
thanks,
Jamie
Here's the code:
Code:
void CvGame::doWatchtowerManage(CvPlot * pPlot)
{
int iSearchRadius = GC.getDefineINT("MAXIMUM_EXTENDED_VISIBILITY_RADIUS");
int iX = pPlot->getX_INLINE();
int iY = pPlot->getY_INLINE();
CvPlot * iterPlot;
ImprovementTypes eImprovement;
CvImprovementInfo pImprovement;
int iRadius = 0;
for (int x = iX - iSearchRadius; x <= iX + iSearchRadius; x++)
{
if (x < 0 || x > GC.getMapINLINE().getGridWidthINLINE()-1) continue;
for (int y = iY + iSearchRadius; y >= iY - iSearchRadius; y--)
{
if (y < 0 || y > GC.getMapINLINE().getGridHeightINLINE()-1) continue;
iterPlot = GC.getMapINLINE().plot(x, y);
eImprovement = iterPlot->getImprovementType();
if (eImprovement != NO_IMPROVEMENT)
{
[B] pImprovement = GC.getImprovementInfo(eImprovement);
iRadius = pImprovement.getVisibilityRadius();
if (iRadius == 0) continue;
if (plotDistance(pPlot->getX_INLINE(), pPlot->getY_INLINE(), iterPlot->getX_INLINE(), iterPlot->getY_INLINE()) <= iRadius)
{
//manage visibility
TeamTypes eTeam = iterPlot->getTeam();
TeamTypes ePreviousTeam = iterPlot->getPreviousTeam();
if (ePreviousTeam == eTeam) continue;
else
{
if (eTeam != NO_TEAM && !pPlot->isVisible(eTeam, false)) { pPlot->changeVisibilityCount(eTeam, 1, NO_INVISIBLE, true); }
if (ePreviousTeam != NO_TEAM) { pPlot->changeVisibilityCount(ePreviousTeam, -1, NO_INVISIBLE, true); }
}
}[/B]
}
}
}
return;
}
where the getVisibilityRadius is just an extra field in the improvement infos. Bold represents possible area of crash
thanks,
Jamie