我有一个图形引擎的代码,它需要绘制线框和线条图,我对我的原始代码做了一些调整,现在我得到错误双免费或腐败,但在代码工作之前就好了,有人知道我做错了吗?
void Wireframe::Generate(list<eye_point> &points, list<line> &lines, const ini::Configuration &configuration)
{
string buffer;
stringstream out;
for(int i = 0; i < nrFigures; i++)
{
figure = "Figure";
out<<i;
buffer = out.str();
figure.append(buffer);
out.str(string());
cout<<"de figure heeft de naam "<<figure<<endl;
Read_info(configuration);
Generate_points(points, configuration);
Generate_lines(lines, configuration);
}
}
在读取信息中,他从ini文件中读取信息
void Wireframe::Generate_points(list<eye_point> &points, const ini::Configuration &configuration){
Matrix schaal = Scale(scale);
Matrix translate = Translatie(center);
Matrix xrotate = Rotate_x_as(rotatex);
Matrix yrotate = Rotate_y_as(rotatey);
Matrix zrotate = Rotate_z_as(rotatez);
Matrix eyematrix = Eye_transformatie(eye);
Matrix matrix;
matrix = schaal * translate * xrotate * yrotate * zrotate * eyematrix;
if(type.compare("LineDrawing") == 0)
{
linedrawing_point(points, configuration, matrix);
}
else if(type.compare("Cube") == 0)
{
cube_point(points,matrix);
}
}
void Wireframe::Generate_lines(list<line> &lines, const ini::Configuration &configuration){
if(type.compare("LineDrawing") == 0)
{
linedrawing_lines(lines, configuration);
}
else if (type.compare("Cube") == 0)
{
cube_lines(lines);
}
}
在这里,他看到了他需要做的线条画,通过线条画很好,错误在立方体中。
void Wireframe::cube_lines(list<line> &lines){
getline(lines, 1, 5);
getline(lines, 5, 3);
getline(lines, 3, 7);
getline(lines, 7, 1);
getline(lines, 5, 2);
getline(lines, 2, 8);
getline(lines, 8, 3);
getline(lines, 3, 5);
getline(lines, 2, 6);
getline(lines, 6, 4);
getline(lines, 4, 8);
getline(lines, 8, 2);
getline(lines, 6, 1);
getline(lines, 1, 7);
getline(lines, 7, 4);
getline(lines, 4, 6);
getline(lines, 7, 3);
getline(lines, 3, 8);
getline(lines, 8, 4);
getline(lines, 4, 7);
getline(lines, 1, 6);
getline(lines, 6, 2);
getline(lines, 2, 5);
getline(lines, 5, 1);
}
void Wireframe::cube_point(list<eye_point> &points, Matrix &matrix){
getpoint(1, -1, -1, points, 1, matrix );
getpoint(-1, 1, -1, points, 2, matrix );
getpoint(1, 1, 1, points, 3, matrix );
getpoint(-1, -1, 1, points, 4, matrix );
getpoint(1, 1, -1, points, 5, matrix );
getpoint(-1, -1, -1, points, 6, matrix );
getpoint(1, -1, 1, points, 7, matrix );
getpoint(-1, 1, 1, points, 1, matrix );
}
void Wireframe::projectie(Vector3D &vector_points, eye_point &point_element){
point_element.z = vector_points.z;
if(vector_points.z != 0)
{
point_element.x = vector_points.x / -vector_points.z;
point_element.y = vector_points.y / -vector_points.z;
}
else
{
point_element.x = vector_points.x;
point_element.y = vector_points.y;
}
}
void Wireframe::getpoint(double x, double y, double z, list<eye_point> &points, int nummer, Matrix &matrix ){
eye_point point_element;
Vector3D vector_points = Vector3D::point(x, y, z);
vector_points *= matrix;
point_element.figure = figure;
point_element.punt = nummer;
projectie(vector_points, point_element);
points.push_back(point_element);
}
void Wireframe::getline(list<line> &lines, int lijn0, int lijn1){
line line_element;
line_element.lijn0 = lijn0;
line_element.lijn1 = lijn1;
line_element.figure = figure;
line_element.linecolor = linecolor;
lines.push_back(line_element);
}
答案 0 :(得分:0)
如果你在Windows上,你可能想尝试免费的AppVerifier工具,它旨在检测双重免费错误http://msdn.microsoft.com/en-us/library/ms807121.aspx
答案 1 :(得分:0)
发布的代码不直接进行任何分配或释放,因此与您的错误无关。
您放入容器(line
和eye_point
)的对象可能存在错误。例如,缺少赋值运算符或复制构造函数可能会导致各种令人困惑的行为。