From db58c7c5f95058a90e9e55946eb8a39448c68060 Mon Sep 17 00:00:00 2001 From: Cyp Date: Sat, 23 Oct 2010 08:33:58 +0200 Subject: [PATCH] Fix infinite loop when modifying a template in infinite production. 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. --- src/structure.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/structure.c b/src/structure.c index 0238ceb55..b5789ebcf 100644 --- a/src/structure.c +++ b/src/structure.c @@ -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__); @@ -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++; @@ -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)