diff options
author | Keith Whitwell <keith@tungstengraphics.com> | 2006-05-22 14:58:57 +0000 |
---|---|---|
committer | Keith Whitwell <keith@tungstengraphics.com> | 2006-05-22 14:58:57 +0000 |
commit | 7419b16a2072d179ef24cad6bc799ef57c16bc91 (patch) | |
tree | f87afe91e11bbdd4526aa3667d70dde0f237c919 | |
parent | 267dd12027f1b1960eb55a834bc36a87ff270ed2 (diff) |
Clear cache if it gets too big -- otherwise glean/conform type tests
which do squillions of test combinations will run out of memory.
-rw-r--r-- | src/mesa/main/texenvprogram.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index abff17a6ab..d27bf946a1 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -1128,6 +1128,26 @@ static void rehash( struct texenvprog_cache *cache ) cache->size = size; } +static void clear_cache( struct texenvprog_cache *cache ) +{ + struct texenvprog_cache_item *c, *next; + GLuint i; + + for (i = 0; i < cache->size; i++) { + for (c = cache->items[i]; c; c = next) { + next = c->next; + FREE(c->key); + FREE(c->data); + FREE(c); + } + cache->items[i] = NULL; + } + + + cache->n_items = 0; +} + + static void cache_item( struct texenvprog_cache *cache, GLuint hash, void *key, @@ -1138,9 +1158,14 @@ static void cache_item( struct texenvprog_cache *cache, c->key = key; c->data = data; - if (++cache->n_items > cache->size * 1.5) - rehash(cache); + if (cache->n_items > cache->size * 1.5) { + if (cache->size < 1000) + rehash(cache); + else + clear_cache(cache); + } + cache->n_items++; c->next = cache->items[hash % cache->size]; cache->items[hash % cache->size] = c; } @@ -1200,17 +1225,7 @@ void _mesa_TexEnvProgramCacheInit( GLcontext *ctx ) void _mesa_TexEnvProgramCacheDestroy( GLcontext *ctx ) { - struct texenvprog_cache_item *c, *next; - GLuint i; - - for (i = 0; i < ctx->Texture.env_fp_cache.size; i++) - for (c = ctx->Texture.env_fp_cache.items[i]; c; c = next) { - next = c->next; - FREE(c->key); - FREE(c->data); - FREE(c); - } - + clear_cache(&ctx->Texture.env_fp_cache); FREE(ctx->Texture.env_fp_cache.items); } |