Skip to content

Commit 6818fae

Browse files
authored
bugfix(ai): Fix crash when AI player attempts to build a supply center with an invalid name (TheSuperHackers#2095)
1 parent bd4e909 commit 6818fae

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,8 +1735,15 @@ void AIPlayer::buildUpgrade(const AsciiString &upgrade)
17351735
// ------------------------------------------------------------------------------------------------
17361736
void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName)
17371737
{
1738-
Object *bestSupplyWarehouse = findSupplyCenter(minimumCash);
17391738
const ThingTemplate* tTemplate = TheThingFactory->findTemplate(thingName);
1739+
if (!tTemplate)
1740+
{
1741+
DEBUG_CRASH(("Template %s should exist; check ini and script files.", thingName.str()));
1742+
return;
1743+
}
1744+
1745+
Object *bestSupplyWarehouse = findSupplyCenter(minimumCash);
1746+
17401747
if (!tTemplate->isKindOf(KINDOF_CASH_GENERATOR)) {
17411748
// Build by the current warehouse.
17421749
Object *curWarehouse = TheGameLogic->findObjectByID(m_curWarehouseID);
@@ -1746,7 +1753,7 @@ void AIPlayer::buildBySupplies(Int minimumCash, const AsciiString& thingName)
17461753
}
17471754

17481755

1749-
if (bestSupplyWarehouse && tTemplate) {
1756+
if (bestSupplyWarehouse) {
17501757
Coord3D location;
17511758
location = *bestSupplyWarehouse->getPosition();
17521759
// offset back towards the base.

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)