There is a crash issue in StarCraft 2.
While executing a strategy of defending with Photon Cannons followed by an attack, the simulation would irregularly crash and terminate.
Upon debugging, the problem was traced to building placement. According to bots.py, a building can only be constructed once best_position is determined. When the surrounding area search repeatedly fails to find a suitable location, best_position remains None, causing a crash when attempting to build.
In the bots.py file, within the function:
python
async def handle_action_build_building(self, building_type: UnitTypeId, building_limits=None):
There is this commented section:
python
# if not best_position:
# print(f"Still no suitable position found for {building_type}. Aborting.")
# return
Fix: Uncomment this section so that if best_position cannot be found, the function simply skips the build:
python
if not best_position:
print(f"Still no suitable position found for {building_type}. Aborting.")
return
This change prevents the crash by gracefully handling cases where no valid building location is found, allowing the bot to continue running instead of terminating the simulation.