Skip to content

Unhandled exception: "Factory::updateProduction(): Production cost not empty" #2122

@DanRStevens

Description

@DanRStevens

When running multiple Factory structures, it's possible to get an unhandled exception:

Factory::updateProduction(): Production cost not empty

This stems from the following code:

if (!enoughResourcesAvailable())
{
	idle(IdleReason::FactoryInsufficientResources);
	return;
}

const auto& productionCost = productCost(mProduct);
auto cost = productionCost.resourceCost;

removeRefinedResources(cost);

if (!cost.isEmpty()) { throw std::runtime_error("Factory::updateProduction(): Production cost not empty"); }

The check in enoughResourcesAvailable uses a cached value for the current resources, which is updated once per turn. Meanwhile the removeRefinedResources function can be called multiple times per turn. In particular, it can be called for each factory producing an item. This leads to a discrepancy between the two functions regarding what the current number of resources are, which triggers the sanity check which throws the exception.

Running more factories can increase the likelihood of encountering this error. For a factory to contribute to this problem, it should be producing an item that has a turn cost less than or equal to the current cached resource count (so it doesn't go idle due to lack of resources). The greater the item cost, the more resources will be removed, increasing the likelihood that it exceeds the current actual resources.


Related:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions