我从以下代码中的这一行得到一个断言失败“列表迭代器不可取消引用”:
iter2 = iter->vertex_list.erase(iter2);
我不确定为什么会发生这种情况,我确保列表不为空。完整代码如下:
void Map_Quad_List::Vertex_List_Duplicate_Removal() {
for (std::list<Map_Polygon>::iterator iter = map_polygon_list.begin(); iter != map_polygon_list.end(); iter++) { //iterate through polygons
std::vector<XMFLOAT3> position_list; //list of vertices already tried
for (std::list<Vertex>::iterator iter2 = iter->vertex_list.begin(); iter2 != iter->vertex_list.end(); iter2++ ) {//iterate through vertices
bool dup = false;
for (std::vector<XMFLOAT3>::iterator pos_list_iter = position_list.begin(); pos_list_iter != position_list.end(); pos_list_iter++) { //check vertex against position_list
if ((!position_list.empty()) && (XMFLOAT3_Comparison(*pos_list_iter, iter2->position))) { //if vertex already exists in position_list
iter2 = iter->vertex_list.erase(iter2); //remove vertex from polygon's vertex_list
dup = true;
}
}
if (dup == false) //if there is not a duplicate in position_list, add it to position_list
position_list.push_back(iter2->position);
}
}
}
map_polygon_list 是类类型 Map_Polygon 的 std::list
Map_Polygon 类具有类类型 Vertex 的 std::list
Vertex是一个由一个XMFLOAT3(位置)和一个XMFLOAT4(颜色)组成的类,这个函数只处理位置(XMFLOAT3)
XMFLOAT3_Comparison 是一个比较两个 XMFLOAT3 的函数,如果它们相同则返回 true