B
Brad Moore
Hey All,
I need help with debugging some code, if this isn't the correct
newsgroup to ask in, disregard this message.
I'm having difficulty pinpointing a memory leak in my code, I believe it
has something to do with an inherited class I have, but I fail to see
anything wrong. Here is the problematic code. I've hunted the bug down
to this function using gdb and commenting out parts of my code. I
originally used CIntersect as a base class and inherited from it, but
even without inheriting it still causes a bus error.
SbColor shadeRay(OSUInventorScene * scene, SbLine &ray, int recur,
int maxRecur)
{
int numObjects = scene->Objects.getLength();
SbColor color(0,0,0);
OSUObjectData * obj;
CIntersect * intersect = 0;
float distance = -1.0;
if (recur >= maxRecur)
return color;
// calculate intersection point
for (int i = 0; i < numObjects; i++) {
OSUObjectData * tempObj = (OSUObjectData *)scene->Objects;
CIntersect * tempIntersect = 0;
tempIntersect = new CIntersect();
float tempDis = tempIntersect->getDistance();
if ((tempDis > 0) && ( tempDis < distance || distance == -1.0)) {
distance = tempDis;
obj = tempObj;
if (intersect != 0)
delete intersect;
intersect = tempIntersect;
}
}
if (intersect != 0)
delete intersect;
return color;
}
I've commented out objects, replaced them with dummy's, and it seems
that is it the CIntersect class that is causing the memory leak.
class CIntersect {
public:
CIntersect() { }
virtual ~CIntersect() { }
CIntersect(OSUObjectData * m_obj, SbLine& ray)
{
this->m_obj = m_obj;
}
SbVec3f getPoint() { return m_point; }
SbVec3f getNormal() { return m_normal; }
SbVec3f getIncoming() { return m_incoming; }
float getDistance() { return m_distance; }
OSUObjectData * getObject() { return m_obj; }
bool isFrontFace() { return m_isFrontFace; }
protected:
SbVec3f m_normal;
SbVec3f m_point;
SbVec3f m_incoming;
float m_distance;
bool m_isFrontFace;
OSUObjectData * m_obj;
};
Honestly, this isn't my original code, but this is the exact copy of the
mininum set of code I can come to and still cause the bus error. I
consider this a memory leak because the bus error occurs only when I
call shadeRay() a large amount of times. All the other non-standard
types are from tried and true libraries, so once again, I believe the
code at fault is CIntersect.
If you don't see anything wrong with this code, it'll still be a great
help because I'll then know to look elsewhere.
Thanks for any help,
-Brad
I need help with debugging some code, if this isn't the correct
newsgroup to ask in, disregard this message.
I'm having difficulty pinpointing a memory leak in my code, I believe it
has something to do with an inherited class I have, but I fail to see
anything wrong. Here is the problematic code. I've hunted the bug down
to this function using gdb and commenting out parts of my code. I
originally used CIntersect as a base class and inherited from it, but
even without inheriting it still causes a bus error.
SbColor shadeRay(OSUInventorScene * scene, SbLine &ray, int recur,
int maxRecur)
{
int numObjects = scene->Objects.getLength();
SbColor color(0,0,0);
OSUObjectData * obj;
CIntersect * intersect = 0;
float distance = -1.0;
if (recur >= maxRecur)
return color;
// calculate intersection point
for (int i = 0; i < numObjects; i++) {
OSUObjectData * tempObj = (OSUObjectData *)scene->Objects;
CIntersect * tempIntersect = 0;
tempIntersect = new CIntersect();
float tempDis = tempIntersect->getDistance();
if ((tempDis > 0) && ( tempDis < distance || distance == -1.0)) {
distance = tempDis;
obj = tempObj;
if (intersect != 0)
delete intersect;
intersect = tempIntersect;
}
}
if (intersect != 0)
delete intersect;
return color;
}
I've commented out objects, replaced them with dummy's, and it seems
that is it the CIntersect class that is causing the memory leak.
class CIntersect {
public:
CIntersect() { }
virtual ~CIntersect() { }
CIntersect(OSUObjectData * m_obj, SbLine& ray)
{
this->m_obj = m_obj;
}
SbVec3f getPoint() { return m_point; }
SbVec3f getNormal() { return m_normal; }
SbVec3f getIncoming() { return m_incoming; }
float getDistance() { return m_distance; }
OSUObjectData * getObject() { return m_obj; }
bool isFrontFace() { return m_isFrontFace; }
protected:
SbVec3f m_normal;
SbVec3f m_point;
SbVec3f m_incoming;
float m_distance;
bool m_isFrontFace;
OSUObjectData * m_obj;
};
Honestly, this isn't my original code, but this is the exact copy of the
mininum set of code I can come to and still cause the bus error. I
consider this a memory leak because the bus error occurs only when I
call shadeRay() a large amount of times. All the other non-standard
types are from tried and true libraries, so once again, I believe the
code at fault is CIntersect.
If you don't see anything wrong with this code, it'll still be a great
help because I'll then know to look elsewhere.
Thanks for any help,
-Brad