我尝试从 vector3f 访问/打印数据,结果是EXC_BAD_ACCESS
:
std::cout << myMesh.faces[1].vertices[1].pos.x;
代码:
struct Vector2f{
float x, y;
};
struct Vector3f{
float x, y, z;
};
struct ObjMeshVertex{
Vector3f pos;
Vector2f texcoord;
Vector3f normal;
};
struct ObjMeshFace{
ObjMeshVertex vertices[3];
ObjMeshFace(){}
ObjMeshFace(const ObjMeshFace& o)
{for (int i=0; i < 3; ++i) vertices[i] = o.vertices[i]; }
};
struct ObjMesh{
std::vector<ObjMeshFace> faces;
};
ObjMesh myMesh;
for(size_t i = 0; i < faces.size(); ++i){
ObjMeshFace face;
for(size_t j = 0; j < 3; ++j){
face.vertices[j].pos = positions[(faces[i].pos_index[j] - 1)];
face.vertices[j].texcoord = texcoords[faces[i].tex_index[j] - 1];
face.vertices[j].normal = normals[faces[i].nor_index[j] - 1];
}
myMesh.faces.push_back(face);
}
调试器指的是stl_vector.h
:
reference
operator[](size_type __n)
{ return *(this->_M_impl._M_start + __n); }
这是什么意思?我打电话超出范围了吗?