Skip to content

Commit e645451

Browse files
committed
bugfix(AIPlayer): Fix crash when AI player attempts to build supply center with invalid name
1 parent 8c560e6 commit e645451

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,8 +1859,15 @@ void AIPlayer::buildUpgrade(const AsciiString &upgrade)
18591859
// ------------------------------------------------------------------------------------------------
18601860
void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName)
18611861
{
1862-
Object *bestSupplyWarehouse = findSupplyCenter(minimumCash);
18631862
const ThingTemplate* tTemplate = TheThingFactory->findTemplate(thingName);
1863+
if (!tTemplate)
1864+
{
1865+
DEBUG_CRASH(("Template %s should exist; check ini and script files.", thingName.str()));
1866+
return;
1867+
}
1868+
1869+
Object *bestSupplyWarehouse = findSupplyCenter(minimumCash);
1870+
18641871
if (!tTemplate->isKindOf(KINDOF_CASH_GENERATOR)) {
18651872
// Build by the current warehouse.
18661873
Object *curWarehouse = TheGameLogic->findObjectByID(m_curWarehouseID);
@@ -1870,7 +1877,7 @@ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName)
18701877
}
18711878

18721879

1873-
if (bestSupplyWarehouse && tTemplate) {
1880+
if (bestSupplyWarehouse) {
18741881
Coord3D location;
18751882
location = *bestSupplyWarehouse->getPosition();
18761883
// offset back towards the base.

0 commit comments

Comments
 (0)