IsoRTS icon indicating copy to clipboard operation
IsoRTS copied to clipboard

Potential crash in simpleAI.cpp

Open Ruckamongus opened this issue 5 years ago • 1 comments

The last return statement in the implementation of "int distanceToResource(int, cords)," currently line 135, has the potential to crash as it may dereference the front() of an empty list.

int distanceToResource(int kind, cords from)
{
	std::list <nearestBuildingTile> listOfResourceLocations;

	if (!listOfObjects.empty()) { ... }

	if (!listOfResourceLocations.empty()) { ... }

	return listOfResourceLocations.front().deltaDistance;
        //Crash here if both of the above if statements are false since listOfResourceLocations is empty
}

Ruckamongus avatar Aug 03 '21 02:08 Ruckamongus

Thanks for catching that. I made it return a really long distance until a add code to make the AI deal with a resource which is unavailble. For now it should not matter for placing buildings. All the spots will have the same 'penalty' of 9999

switchboy avatar Aug 03 '21 11:08 switchboy