I am encountering the error '0xC000041D: An unhandled exception was encountered during a user callback', when I run the OpenGL code. Th debugger indicates that the error occurs here:
The function where the error occurs and calling functions are given below.
Could you please help me identify the cause for this error.
double maxDistance(Point_2D* bez, int deg)
{
int i;
double maxheight;
double height[30];
// Computing baseline vector and its magnitude
Point_2D baselineVector;
baselineVector.x = bez[deg].x - bez[0].x;
baselineVector.y = bez[deg].y - bez[0].y;
double baselineMag = sqrt((baselineVector.x*baselineVector.x) + (baselineVector.y*baselineVector.y));
double crossprod[3];
double crossprodMag;
// Computing height of a intermediate control points from baseline
Point_2D cpVector; // Vector from first control point to intermediate control point
for (i = 1; i < deg; i++)
{
cpVector.x = bez[i].x - bez[0].x;
cpVector.y = bez[i].y - bez[0].y;
// Computing cross product of baseline vector and control point vector
//z coordinates of baseline and control point vectors are 0
crossprod[0] = ((baselineVector.y * 0) - (0 * cpVector.y));
crossprod[1] = -((baselineVector.x * 0) - (0 * cpVector.x));
crossprod[2] = ((baselineVector.x * cpVector.y) - (baselineVector.y * cpVector.x));
crossprodMag = sqrt((crossprod[0] * crossprod[0]) + (crossprod[1] * crossprod[1]) + (crossprod[2] * crossprod[2]));
height[i] = crossprodMag / baselineMag;
}
// Finding maximum height of a control point from baseline
maxheight = height[0];
for (i = 0; i < deg; i++)
{
if (maxheight < height[i])
maxheight = height[i];
}
return maxheight;
}
void plotBezier(Point_2D* bez, int deg)
{
Point_2D* leftBez= (Point_2D*)malloc((deg + 1)*sizeof(Point_2D));
Point_2D* rightBez=(Point_2D*)malloc((deg + 1)*sizeof(Point_2D));;
double height = maxDistance(bez, deg);
if (height < flat_thresh)
{
drawLine(bez[0], bez[deg]);
return;
}
else
{
midSubdivideBezier(bez, deg, leftBez, rightBez);
plotBezier(leftBez, deg);
plotBezier(rightBez, deg);
}
free(leftBez);
free(rightBez);
}
//============================================================
void adaptiveRender()
{
Point_2D* bez =(Point_2D*) malloc(30 * sizeof(Point_2D)); // assume the degree is not greater than 29.
int i;
for (i = bcr.degree; i< bcr.deBoor_count; i++) // Determining segments between the kth knot and the (n+1)th knot
{
if (!(fabs(bcr.knots[i] - bcr.knots[i + 1]) < 0.00001)) // No segment when adjacent knots are equal
{
extractBezier(bez, i); // Extract the i-th Bezier curve
plotBezier(bez, bcr.degree); // Adaptively plot a Bezier curve
}
}
free(bez);
}