On 26 May 2005, at 14:24, Theo Vosse wrote:
Hi,
I've noticed that calling glutSolidSphere() seems to leak memory.
Launching the application with MallocDebug shows an increase in
leaks every time I draw one. In particular, it allocates these
quadrics, but apparently never releases them.
Am I doing something wrong or is this a bug?
Thanks in advance,
Theo
Apple's GLUT implementation is available at:
http://developer.apple.com/samplecode/glut/glut.html
I had a quick look through the code for glutSolidSphere (from
glut_shapes.c) and have included some relevant bits at the end.
Basically, GLUT is implemented as a subclassed NSOpenGLView with an
instance variable _quadObj which is shared by all GLUT related
calls. However, this only gets deallocated when the application
closes (via the dealloc method). If you want memory deallocated
before application termination then I guess you have to implement
this yourself using the GLU APIs like gluSphere.
#define QUAD_OBJ_INIT() GLUquadricObj *quadObj = __glutGetQuadObj();
void APIENTRY
glutSolidSphere(GLdouble radius, GLint slices, GLint stacks)
{
QUAD_OBJ_INIT();
gluQuadricDrawStyle(quadObj, GLU_FILL);
gluQuadricNormals(quadObj, GLU_SMOOTH);
/* If we ever changed/used the texture or orientation state
of quadObj, we'd need to change it to the defaults here
with gluQuadricTexture and/or gluQuadricOrientation. */
gluSphere(quadObj, radius, slices, stacks);
}
// A helper for quadric objects
GLUquadricObj *__glutGetQuadObj(void)
{
if (__glutViewList == NULL) // This means you never initialized
GLUT - BUT you are still allowed to call glutWireShphere()
// and such anyway. Fixes bug
#2742838
return gluNewQuadric();
return [__glutCurrentView _getQuadObj];
}
- (GLUquadricObj *)_getQuadObj
{
if (_quadObj == NULL)
_quadObj = gluNewQuadric();
return _quadObj;
}
r i c k
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/jstiles%
40blizzard.com
This email sent to email@hidden