Added _mesa_free_attrib_data() to free anything left in the attribute stack upon context destruction.

Also, a bit more refcount debug info.
This commit is contained in:
Brian 2007-08-15 10:10:02 +01:00
parent 88273e08b4
commit 42c91eebc9
5 changed files with 112 additions and 10 deletions

View file

@ -343,7 +343,9 @@ _mesa_PushAttrib(GLbitfield mask)
* inadvertantly get deleted.
*/
#ifdef DEBUG
printf("MESA PUSH TEX ATTRIB, INCR REF COUNT BY %d\n", ctx->Const.MaxTextureUnits);
printf("%lu: MESA PUSH TEX ATTRIB, INCR REF COUNT BY %d\n",
_glthread_GetID(),
ctx->Const.MaxTextureUnits);
#endif
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
@ -798,7 +800,9 @@ pop_texture_group(GLcontext *ctx, const struct gl_texture_attrib *texAttrib)
* inside the attribute state stack.
*/
#ifdef DEBUG
printf("MESA POP TEX ATTRIB, DECR REF COUNT BY %d\n", ctx->Const.MaxTextureUnits);
printf("%lu: MESA POP TEX ATTRIB, DECR REF COUNT BY %d\n",
_glthread_GetID(),
ctx->Const.MaxTextureUnits);
#endif
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
ctx->Texture.Unit[u].Current1D->RefCount--;
@ -1409,6 +1413,84 @@ _mesa_PopClientAttrib(void)
}
static struct gl_texture_object *
get_texobj(GLcontext *ctx, GLenum target, GLuint name)
{
struct gl_texture_object *texObj;
if (name) {
texObj = _mesa_lookup_texture(ctx, name);
}
else {
switch (target) {
case GL_TEXTURE_1D:
texObj = ctx->Shared->Default1D;
break;
case GL_TEXTURE_2D:
texObj = ctx->Shared->Default2D;
break;
case GL_TEXTURE_3D:
texObj = ctx->Shared->Default3D;
break;
case GL_TEXTURE_CUBE_MAP_ARB:
texObj = ctx->Shared->DefaultCubeMap;
break;
case GL_TEXTURE_RECTANGLE_NV:
texObj = ctx->Shared->DefaultRect;
break;
default:
abort();
}
}
return texObj;
}
void
_mesa_free_attrib_data(GLcontext *ctx)
{
#ifdef DEBUG
printf("%lu: MESA FREEING ATTRIB STACK DATA\n",
_glthread_GetID());
#endif
while (ctx->AttribStackDepth > 0) {
struct gl_attrib_node *attr, *next;
ctx->AttribStackDepth--;
attr = ctx->AttribStack[ctx->AttribStackDepth];
while (attr) {
struct gl_texture_attrib *texAttrib
= (struct gl_texture_attrib *) attr->data;
GLuint u;
for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {
struct gl_texture_unit *unit = &texAttrib->Unit[u];
struct gl_texture_object *texObj;
texObj = get_texobj(ctx, GL_TEXTURE_1D, unit->Saved1D.Name);
MESA_REF_TEXOBJ(&texObj, NULL);
texObj = get_texobj(ctx, GL_TEXTURE_2D, unit->Saved2D.Name);
MESA_REF_TEXOBJ(&texObj, NULL);
texObj = get_texobj(ctx, GL_TEXTURE_3D, unit->Saved3D.Name);
MESA_REF_TEXOBJ(&texObj, NULL);
texObj = get_texobj(ctx, GL_TEXTURE_CUBE_MAP, unit->SavedCubeMap.Name);
MESA_REF_TEXOBJ(&texObj, NULL);
texObj = get_texobj(ctx, GL_TEXTURE_RECTANGLE_NV, unit->SavedRect.Name);
MESA_REF_TEXOBJ(&texObj, NULL);
}
next = attr->next;
_mesa_free(attr->data);
_mesa_free(attr);
attr = next;
}
}
#ifdef DEBUG
printf("%lu: MESA DONE FREEING ATTRIB STACK DATA\n",
_glthread_GetID());
#endif
}
void _mesa_init_attrib( GLcontext *ctx )
{
/* Renderer and client attribute stacks */

View file

@ -58,10 +58,14 @@ _mesa_PopClientAttrib( void );
extern void
_mesa_init_attrib( GLcontext *ctx );
extern void
_mesa_free_attrib_data( GLcontext *ctx );
#else
/** No-op */
#define _mesa_init_attrib( c ) ((void)0)
#define _mesa_free_attrib_data( c ) ((void)0)
#endif

View file

@ -1194,7 +1194,8 @@ _mesa_free_context_data( GLcontext *ctx )
if (ctx->AttribStackDepth > 0) {
#ifdef DEBUG
printf("MESA: DESTROY CONTEXT WITH NON-EMPTRY ATTRIB STACK!\n");
printf("%lu: MESA: DESTROY CONTEXT WITH NON-EMPTRY ATTRIB STACK!\n",
_glthread_GetID());
#endif
}
@ -1204,6 +1205,7 @@ _mesa_free_context_data( GLcontext *ctx )
_mesa_unreference_framebuffer(&ctx->DrawBuffer);
_mesa_unreference_framebuffer(&ctx->ReadBuffer);
_mesa_free_attrib_data(ctx);
_mesa_free_lighting_data( ctx );
_mesa_free_eval_data( ctx );
_mesa_free_texture_data( ctx );

View file

@ -155,7 +155,9 @@ _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
GLuint i, face;
#ifdef DEBUG
printf("MESA TEX DELETE %p (%u)\n", (void*) texObj, texObj->Name);
printf("%lu: MESA TEX DELETE %p (%u) REF COUNT = %d\n",
_glthread_GetID(),
(void*) texObj, texObj->Name, texObj->RefCount);
#endif
(void) ctx;
@ -280,7 +282,8 @@ _mesa_reference_texobj(struct gl_texture_object **ptr,
oldTex->RefCount--;
#ifdef DEBUG
printf("MESA TEX REF DECR %p (%u) to %d from %s\n",
printf("%lu: MESA TEX REF DECR %p (%u) to %d from %s\n",
_glthread_GetID(),
(void*) oldTex, oldTex->Name, oldTex->RefCount, where);
#endif
@ -313,7 +316,8 @@ _mesa_reference_texobj(struct gl_texture_object **ptr,
tex->RefCount++;
#ifdef DEBUG
printf("MESA TEX REF INCR %p (%u) to %d from %s\n",
printf("%lu: MESA TEX REF INCR %p (%u) to %d from %s\n",
_glthread_GetID(),
(void*) tex, tex->Name, tex->RefCount, where);
#endif

View file

@ -3109,12 +3109,22 @@ _mesa_init_texture(GLcontext *ctx)
/**
* Free dynamically-allocted texture data attached to the given context.
* Free dynamically-allocated texture data attached to the given context.
*/
void
_mesa_free_texture_data(GLcontext *ctx)
{
GLuint i;
GLuint u;
/* unreference current textures */
for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) {
struct gl_texture_unit *unit = ctx->Texture.Unit + u;
MESA_REF_TEXOBJ(&unit->Current1D, NULL);
MESA_REF_TEXOBJ(&unit->Current2D, NULL);
MESA_REF_TEXOBJ(&unit->Current3D, NULL);
MESA_REF_TEXOBJ(&unit->CurrentCubeMap, NULL);
MESA_REF_TEXOBJ(&unit->CurrentRect, NULL);
}
/* Free proxy texture objects */
(ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D );
@ -3123,8 +3133,8 @@ _mesa_free_texture_data(GLcontext *ctx)
(ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap );
(ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect );
for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
_mesa_free_colortable_data( &ctx->Texture.Unit[i].ColorTable );
for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++)
_mesa_free_colortable_data( &ctx->Texture.Unit[u].ColorTable );
_mesa_TexEnvProgramCacheDestroy( ctx );
}