Reputation: 13
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?
Upvotes: 0
Views: 2278
Reputation: 63735
You don't ever create a TriangleStrip
.
This creates a pointer to a TriangleStrip
.
TriangleStrip* s;
And this expects the pointer to be assigned to a TriangleStrip
. But that never happened.
s->addTriangle(triangles[i]);
Upvotes: 0
Reputation: 258558
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]);
Upvotes: 3