我有一個圖形引擎的代碼,它需要繪製線框和線條圖,我對我的原始代碼進行了一些調整,現在我得到錯誤雙免費或腐敗,但在代碼工作正常之前,annybody知道我做錯了什麼嗎?雙免費或腐敗的錯誤C++
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);
}
你至少可以編輯你的問題,包括髮生問題的堆棧跟蹤或行號。這是一個在網絡瀏覽器中嘗試和調試的代碼__lot__ ...... – talonmies 2012-02-29 11:27:02
在'valgrind'或類似的工具下運行你的代碼。 (我敢打賭,這個bug是在你的'line'類中,可能是[規則3](違反http://en.wikipedia.org/wiki/Rule_of_three_%28C%2B%2B_programming%29)。) – 2012-02-29 11:35:10
其實,它可以在你傳遞給'push_back'的任何類中。最有可能的是你修改的任何課程。確保你的拷貝構造函數和賦值操作符不會在析構函數'free'指針的情況下執行每個成員的拷貝! (否則,銷燬在'push_back'中創建的副本會導致雙倍空閒。) – 2012-02-29 11:41:44