Fix segmentation fault in _tnl_ProgramCacheDestroy().
authorAapo Tahkola <aet@rasterburn.org>
Tue, 1 Nov 2005 15:43:06 +0000 (15:43 +0000)
committerAapo Tahkola <aet@rasterburn.org>
Tue, 1 Nov 2005 15:43:06 +0000 (15:43 +0000)
src/mesa/tnl/t_context.c
src/mesa/tnl/t_vp_build.c

index cda4cf2cbd4d9d23b0ebb9486f8146a9af6719a5..ded62aee594173c2a1e8f803a470d53f48f403c2 100644 (file)
@@ -87,10 +87,19 @@ _tnl_CreateContext( GLcontext *ctx )
    _tnl_array_init( ctx );
    _tnl_vtx_init( ctx );
 
-   if (ctx->_MaintainTnlProgram) 
+   if (ctx->_MaintainTnlProgram) {
+      tnl->vp_cache = MALLOC(sizeof(*tnl->vp_cache));
+      tnl->vp_cache->size = 5;
+      tnl->vp_cache->n_items = 0;
+      tnl->vp_cache->items = MALLOC(tnl->vp_cache->size *
+                               sizeof(*tnl->vp_cache->items));
+      _mesa_memset(tnl->vp_cache->items, 0, tnl->vp_cache->size *
+                               sizeof(*tnl->vp_cache->items));
+      
       _tnl_install_pipeline( ctx, _tnl_vp_pipeline );
-   else 
+   } else {
       _tnl_install_pipeline( ctx, _tnl_default_pipeline );
+   }
 
    /* Initialize the arrayelt helper
     */
@@ -135,7 +144,8 @@ _tnl_DestroyContext( GLcontext *ctx )
    _tnl_destroy_pipeline( ctx );
    _ae_destroy_context( ctx );
 
-   _tnl_ProgramCacheDestroy( ctx );
+   if (ctx->_MaintainTnlProgram)
+      _tnl_ProgramCacheDestroy( ctx );
 
    FREE(tnl);
    ctx->swtnl_context = NULL;
index 8e52e7125c372d9b9b1fb660b84d1da3a0bea2b0..02e5a2aa1b9287bb1b08cc991cc90ec9c3284ed3 100644 (file)
@@ -1479,16 +1479,6 @@ void _tnl_UpdateFixedFunctionProgram( GLcontext *ctx )
    key = make_state_key(ctx);
    hash = hash_key(key);
 
-   if (tnl->vp_cache == NULL) {
-      tnl->vp_cache = MALLOC(sizeof(*tnl->vp_cache));
-      tnl->vp_cache->size = 5;
-      tnl->vp_cache->n_items = 0;
-      tnl->vp_cache->items = MALLOC(tnl->vp_cache->size *
-                               sizeof(*tnl->vp_cache->items));
-      _mesa_memset(tnl->vp_cache->items, 0, tnl->vp_cache->size *
-                               sizeof(*tnl->vp_cache->items));
-   }
-
    /* Look for an already-prepared program for this state:
     */
    ctx->_TnlProgram = (struct vertex_program *)