I have the following function:
void CGlEngineFunctions::GetBezierOpposite( const POINTFLOAT &a,const POINTFLOAT ¢er, POINTFLOAT &b, float blength )
{
POINTFLOAT v;
v.x = a.x - center.x;
v.y = a.y - center.y;
float alength = GetDistance(a,center);
if(blength == 0)
{
blength = alength;
}
float multiplier = blength / alength;
b.x = center.x - multiplier * v.x;
b.y = center.y - multiplier * v.y;
}
I have narrowed the problem down to the least 2 lines:
b.x = center.x - multiplier * v.x;
b.y = center.y - multiplier * v.y;
Every time I call this repeatedly, memory shots up until it crashes.
I use it like this:
glEngine.functions.GetBezierOpposite(usrpt[0].LeftHandle,
usrpt[0].UserPoint,usrpt[0].RightHandle,0);
I really do not see how this could cause any problems.
To test, I changed it to this:
void CGlEngineFunctions::GetBezierOpposite( const POINTFLOAT &a,const POINTFLOAT ¢er, POINTFLOAT &b, float blength )
{
POINTFLOAT v;
v.x = a.x - center.x;
v.y = a.y - center.y;
float alength = GetDistance(a,center);
if(blength == 0)
{
blength = alength;
}
float multiplier = blength / alength;
b.x = 5;
b.y = 5;
}
When I do this it has absolutely no issues. I do not see how doing arithmetic can cause the memory usage to shoot up.
Thanks
could it be cause if alength and blength = 0?
POINTFLOAT:
float x;
float y;
If the
GetDistancecalls this method, there may be a Stack Overflow.If other threads call this method, there may be a Stack Overflow.
Check the POINTFLOAT definition. IMHO, it should be modified to provide subtraction operations. You should not need to reference any of the structure’s members. But then this comment would be about C++.
You should remove the ‘C’ language tag, since the C language does not provide a scope resolution operator, ‘::’.