asmaa.almousa

05-08-2015, 08:54 AM

i am writing a code to get the bezier surface,

It is all working fine and i get the surface finally, but when I try to increase the subdivisions for for the surface, i get this error: "Vector subscript out of range" i tried to fix it in many ways but it didn't work, although increasing and decreasing the subdivisions for the U curves is working only before drawing the v curves and the quads.

the error appears in this line: ctrl_points_v[i].push_back(bezier_curve_points_u[x][i]);

in the following function:

void makeVcurve()

{

ctrl_points_v.resize(subdivision + 1);

bezier_curve_points_v.resize(subdivision + 1);

if (v_curves)

{

if ((ctrl_points_u[1].size() >= 2) && (ctrl_points_u[0].size() >= 2))

{

for (int i = 0; i < subdivision + 1; i++)

{

ctrl_points_v[i].clear();

for (int x = 0; x < total_curves; x++) //count of the total uCurves

{

if (bezier_curve_points_u[x].size() > 0)

ctrl_points_v[i].push_back(bezier_curve_points_u[x][i]);

}

}

}

for (int i = 0; i < subdivision + 1;i++)

{

if (ctrl_points_v[i].size()>=2)

{

bezier_curve_points_v[i].clear();

bezier_curve_points_v[i] = BezierCurve(ctrl_points_v[i], subdivision);

}

}

}

glutPostRedisplay();

}

It is all working fine and i get the surface finally, but when I try to increase the subdivisions for for the surface, i get this error: "Vector subscript out of range" i tried to fix it in many ways but it didn't work, although increasing and decreasing the subdivisions for the U curves is working only before drawing the v curves and the quads.

the error appears in this line: ctrl_points_v[i].push_back(bezier_curve_points_u[x][i]);

in the following function:

void makeVcurve()

{

ctrl_points_v.resize(subdivision + 1);

bezier_curve_points_v.resize(subdivision + 1);

if (v_curves)

{

if ((ctrl_points_u[1].size() >= 2) && (ctrl_points_u[0].size() >= 2))

{

for (int i = 0; i < subdivision + 1; i++)

{

ctrl_points_v[i].clear();

for (int x = 0; x < total_curves; x++) //count of the total uCurves

{

if (bezier_curve_points_u[x].size() > 0)

ctrl_points_v[i].push_back(bezier_curve_points_u[x][i]);

}

}

}

for (int i = 0; i < subdivision + 1;i++)

{

if (ctrl_points_v[i].size()>=2)

{

bezier_curve_points_v[i].clear();

bezier_curve_points_v[i] = BezierCurve(ctrl_points_v[i], subdivision);

}

}

}

glutPostRedisplay();

}