是否有人使用 BWAPI 在访问当前游戏的 Unit 对象时遇到访问冲突错误?
我确定该错误不在我的代码中..无论如何..我可以做些什么来避免访问冲突?
我有时会在下面的评论中遇到这个错误。。下面的代码执行了很多次,只是有时我会收到错误。
int Squad::getSize() {
int no = 0;
for (int i = 0; i < (int) agents.size(); i++) {
BaseAgent* agent = agents.at(i);
if (agent != NULL && agent->isAlive() && agent->getUnit() != NULL && !agent->getUnit()->isBeingConstructed()) // this line
no++;
}
return no;
}
这是我用来从向量中删除 BaseAgent 的代码。分析一下,看看我能不能做得更好:
void AgentManager::cleanup() {
//Step 2. Do the cleanup.
int cnt = 0;
int oldSize = (int)agents.size();
for (int i = 0; i < (int)agents.size(); i++) {
if (!agents.at(i)->isAlive()) {
delete agents.at(i);
agents.erase(agents.begin() + i);
cnt++;
i--;
}
}
int newSize = (int)agents.size();
}
BaseAgent 代码在此链接上