My program crashes here:
void TriangleStrip::addTriangle(Triangle t){
cout << t <<endl ;
instances.push_back(t); // problem here
}
instances is:
vector<Triangle> instances;
I call addTriangle here:
TriangleStrip* s;
int c = m.getTrianglesCount();
int i;
Triangle* triangles = m.getTriangles();
for(i=0; i<c; i++){
s->addTriangle(triangles[i]);
}
cout write me the triangle, but I can't put this to the vector.
What is the problem?
TriangleStrip* s;
declares an uninitialized pointer, and dereferencing it s->addTriangle...
is illegal.
Either initialize it with new
, or don't use pointers at all - in this case you don't need pointers, just have
TriangleStrip s;
and
s.addTriangle(triangles[i]);