Hi.
I am developing a 3d application in SuSE Linux 9.0 in C++.
I ported the application in WinXP using VStudio2003. The fun stuff is that
the application executes in Linux but it crashes immediatelly in WinXP.
I think i found what is causing the segfault in windows.
I have the following classes (which are bad-coded by the way ;) :
class Vertex3d
{
public:
double x,y,z;
long num;
Vertex3d()
{
x = 0;
y = 0;
z = 0;
num = 0;
}
/* Creates a new instance of Vertex3d */
Vertex3d(double x_,double y_,double z_,long num)
{
x = x_;
y = y_;
z = z_;
this->num = num;
}
int draw()
{
glBegin(GL_POINTS);
glVertex3d(x, y, z);
glEnd();
return 0;
}
int draw(double px,double py,double pz)
{
glBegin(GL_POINT)
glVertex3d(px, py, pz);
glEnd();
return 0;
}
double distance(Vertex3d t)
{
return sqrt(pow(((Vertex3d)t).x - x , 2) +
pow(((Vertex3d)t).y - y , 2) +
pow(((Vertex3d)t).z - z , 2));
}
};
#include "Vertex3d.h"
class Cone
{
public:
GLuint selectionName;
bool isSelected;
Vertex3d bottomCentre;
double bottomRadius;
Vertex3d topCentre;
double topRadius;
float* vertices1;
float* vertices2;
float* Upper;
float* Lower;
float *table;
Cone()
{
;
}
Cone(Vertex3d bottomCentre, double bottomRadius, Vertex3d topCentre,
double topRadius)
{
this->bottomCentre = bottomCentre;
this->bottomRadius = bottomRadius;
this->topCentre = topCentre;
this->topRadius = topRadius;
selectionName = 0;
isSelected = false;
vertices1 = (float *)malloc( sizeof(float) * 2 * (30 + 1) );
vertices2 = (float *)malloc( sizeof(float) * 2 * (30 + 1) );
Upper = (float *)malloc( sizeof(float) * 3 * (30 + 1) );
Lower = (float *)malloc( sizeof(float) * 3 * (30 + 1) );;
}
};
In the begining of the main.cpp i do the following:
float x=2.0, y=6.0f, z=1.5;
Cone cone1(Vertex3d(10*x, 0, 10*z, 100), 1, Vertex3d(10*x, 0, 10*z+5, 2), 0.00);
Cone cone2(Vertex3d(9*x, 0, 9*z, 100), 0.7, Vertex3d(9*x, 0, 9*z+3, 2), 0.00);
Cone cone3(Vertex3d(9*x, 0, 11*z, 100), 0.7, Vertex3d(9*x, 0, 11*z+3, 2), 0.00);
Cone cone4(Vertex3d(11*x, 0, 9*z, 100), 0.7, Vertex3d(11*x, 0, 9*z+3, 2), 0.00);
Cone cone5(Vertex3d(11*x, 0, 11*z, 100), 0.7, Vertex3d(11*x, 0, 11*z+3, 2), 0.00);
I think that the previous declarations cause my app to crash in WinXP. Why
does this happens in WinXP although the app runs in Linux?
thanks.