Skip to content

Commit

Permalink
Fix infinite loop when modifying a template in infinite production.
Browse files Browse the repository at this point in the history
If a factory was set to infinite production, but no templates were in the production queue, there was an infinite loop looking for something to produce.
  • Loading branch information
Cyp committed Oct 23, 2010
1 parent 29413f5 commit db58c7c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/structure.c
Expand Up @@ -7009,6 +7009,7 @@ DROID_TEMPLATE * factoryProdUpdate(STRUCTURE *psStructure, DROID_TEMPLATE *psTem
{
UDWORD inc, factoryType, factoryInc;
FACTORY *psFactory;
bool somethingInQueue = false;

CHECK_STRUCTURE(psStructure);
ASSERT_OR_RETURN(NULL, psStructure->player == productionPlayer, "%s called for incorrect player", __FUNCTION__);
Expand All @@ -7022,6 +7023,8 @@ DROID_TEMPLATE * factoryProdUpdate(STRUCTURE *psStructure, DROID_TEMPLATE *psTem
//find the entry in the array for this template
for (inc=0; inc < MAX_PROD_RUN; inc++)
{
somethingInQueue = somethingInQueue || asProductionRun[factoryType][factoryInc][inc].quantity != 0;

if (asProductionRun[factoryType][factoryInc][inc].psTemplate != NULL && asProductionRun[factoryType][factoryInc][inc].psTemplate->multiPlayerID == psTemplate->multiPlayerID)
{
asProductionRun[factoryType][factoryInc][inc].built++;
Expand All @@ -7043,6 +7046,11 @@ DROID_TEMPLATE * factoryProdUpdate(STRUCTURE *psStructure, DROID_TEMPLATE *psTem
return asProductionRun[factoryType][factoryInc][inc].psTemplate;
}
}
// Check that we aren't looping doing nothing.
if (!somethingInQueue)
{
psFactory->productionLoops = 0; // Don't do nothing infinitely many times.
}
/*If you've got here there's nothing left to build unless factory is
on loop production*/
if (psFactory->productionLoops != 0)
Expand Down

0 comments on commit db58c7c

Please sign in to comment.