[solved] C++ question / PQ::Element suddenly has no name
Posted: Tue May 30, 2017 7:59 am
I'm working on the imperial stockpile and encounter a C++ behaviour I do not understand.
I have a for loop going through all queue elements looking for imperial
projects (i.e. projects which are allowed to use imperial stockpile)
In the loop the element has the ship design name.
As soon as I leave the loop, the ship design name is not there anymore.
From the log you can see that the name: Comsat is gone in update 4 (which is directly after leaving the scope of the for-loop:
the relevant code part:
full code in the following commit:
https://github.com/agrrr3/freeorion/com ... 5d72b65c04
I'm baffled, can one explain it to me?
I have a for loop going through all queue elements looking for imperial
projects (i.e. projects which are allowed to use imperial stockpile)
In the loop the element has the ship design name.
As soon as I leave the loop, the ship design name is not there anymore.
From the log you can see that the name: Comsat is gone in update 4 (which is directly after leaving the scope of the for-loop:
Code: Select all
ProductionQueue::Update: 3 seems imperial project was saved: ProductionQueue::Element (ProductionItem: BT_SHIP name: Comsatid: 1) (1) x1 (remaining: 1)
ProductionQueue::Update: 3 last seems imperial project was saved: ProductionQueue::Element (ProductionItem: BT_SHIP name: Comsatid: 1) (1) x1 (remaining: 1)
ProductionQueue::Update: 4 seems imperial project was saved: ProductionQueue::Element (ProductionItem: BT_SHIP id: 1) (1) x1 (remaining: 1)
ProductionQueue::Update: 4 last seems imperial project was saved: ProductionQueue::Element (ProductionItem: BT_SHIP id: 1) (1) x1 (remaining: 1)
the relevant code part:
Code: Select all
// type of QueueType is std::deque<ProductionQueue::Element>
QueueType dpsim_queue = sim_queue;
...
std::vector<std::reference_wrapper<ProductionQueue::Element>> imperial_projects;
...
Element* last_one;
for (auto queue_element : dpsim_queue) {
if (queue_element.allowed_imperial_stockpile_use) {
imperial_projects.push_back(std::ref(queue_element));
}
last_one = &queue_element;
if (imperial_projects.size() > 0) DebugLogger() << "ProductionQueue::Update: 3 seems imperial project was saved: " << imperial_projects.back().get().Dump();
if (last_one) DebugLogger() << "ProductionQueue::Update: 3 last seems imperial project was saved: " << (*last_one).Dump();
}
if (imperial_projects.size() > 0) DebugLogger() << "ProductionQueue::Update: 4 seems imperial project was saved: " << imperial_projects.back().get().Dump();
if (last_one) DebugLogger() << "ProductionQueue::Update: 4 last seems imperial project was saved: " << (*last_one).Dump();
https://github.com/agrrr3/freeorion/com ... 5d72b65c04
I'm baffled, can one explain it to me?