I think this may be happening when a stock is completed in the middle of an AI loop and a flagsearch finds it, but there is no reference to it in stock_buildings so stock_buildings.at(inventory_pos) fails for this Inventory.
either add a if (stock_buildings.count(inventory_pos) && before each call...
OR, call update_stocks_pos if an unknown active stock is found inside a flagsearch (find_nearest_inventory?)
I think this may be happening when a stock is completed in the middle of an AI loop and a flagsearch finds it, but there is no reference to it in stock_buildings so stock_buildings.at(inventory_pos) fails for this Inventory.
either add a if (stock_buildings.count(inventory_pos) && before each call...
OR, call update_stocks_pos if an unknown active stock is found inside a flagsearch (find_nearest_inventory?)