I've debugged my other problem back, to the MyMesh
constructor. In this code:
if (hollow) {
numTriangles = n*8;
triangles=new MyTriangle[numTriangles];
if (smooth) numSurfacePoints=n*8;
else numSurfacePoints=n*12;
surfacePoints=new SurfacePoint[numSurfacePoints];
}else {
numTriangles = n*4;
triangles=new MyTriangle[numTriangles];
if (smooth){
numSurfacePoints=n*4;
surfacePoints=new SurfacePoint[numSurfacePoints];
surfacePoints[n*4]=SurfacePoint(vector3(0,0,1),vector3(0,0,1));
surfacePoints[n*4+1]=SurfacePoint(vector3(0,0,-1),vector3(0,0,-1));
}else{
numSurfacePoints=n*6;
surfacePoints=new SurfacePoint[numSurfacePoints];
surfacePoints[n*6]=SurfacePoint(vector3(0,0,1),vector3(0,0,1));
surfacePoints[n*6+1]=SurfacePoint(vector3(0,0,-1),vector3(0,0,-1));
}
}
I'm determining the neccessary SurfacePoints and Triangles for the mesh. The bools "hollow" and "smooth" indicates, if i need a hole in the cone, or if the normals are the same, but i think it's irrevelant.
The problem is: if hollow==false, it does something wrong, but doesn't crashes, it even allows to put the values in the arrays, but when I'm trying to cout it like this:
for(int i=0;i<numSurfacePoints;i++){
std::cout<<"vertex "<<i<<"-> pos:"<<surfacePoints[i].pos.x<<" "<<
surfacePoints[i].pos.y<<" "<<surfacePoints[i].pos.z<<
" norm:"<<surfacePoints[i].norm.x<<" "<<surfacePoints[i].norm.y<<
" "<<surfacePoints[i].norm.z<<"\n";
}
it throws a bad_alloc exception, right when i=0.
additionally, there was a time, when the upper code segment threw a bad_alloc at the operator new, but that problem just solved itself, but maybe it's relevant.
can anybody help me?