meta: Properly refcount our saved programs and texobjs.
authorEric Anholt <eric@anholt.net>
Sat, 13 Mar 2010 01:09:51 +0000 (17:09 -0800)
committerEric Anholt <eric@anholt.net>
Tue, 16 Mar 2010 20:18:53 +0000 (13:18 -0700)
Found while debugging bug #24119.

src/mesa/drivers/common/meta.c

index b97b760f1815da03e06705b28836100765e86d11..b29f58db729f370c88651865f77a0abba3c5c172 100644 (file)
@@ -429,13 +429,15 @@ _mesa_meta_begin(GLcontext *ctx, GLbitfield state)
    if (state & META_SHADER) {
       if (ctx->Extensions.ARB_vertex_program) {
          save->VertexProgramEnabled = ctx->VertexProgram.Enabled;
-         save->VertexProgram = ctx->VertexProgram.Current;
+         _mesa_reference_vertprog(ctx, &save->VertexProgram,
+                                 ctx->VertexProgram.Current);
          _mesa_set_enable(ctx, GL_VERTEX_PROGRAM_ARB, GL_FALSE);
       }
 
       if (ctx->Extensions.ARB_fragment_program) {
          save->FragmentProgramEnabled = ctx->FragmentProgram.Enabled;
-         save->FragmentProgram = ctx->FragmentProgram.Current;
+         _mesa_reference_fragprog(ctx, &save->FragmentProgram,
+                                 ctx->FragmentProgram.Current);
          _mesa_set_enable(ctx, GL_FRAGMENT_PROGRAM_ARB, GL_FALSE);
       }
 
@@ -663,6 +665,7 @@ _mesa_meta_end(GLcontext *ctx)
                           save->VertexProgramEnabled);
          _mesa_reference_vertprog(ctx, &ctx->VertexProgram.Current, 
                                   save->VertexProgram);
+        _mesa_reference_vertprog(ctx, &save->VertexProgram, NULL);
       }
 
       if (ctx->Extensions.ARB_fragment_program) {
@@ -670,6 +673,7 @@ _mesa_meta_end(GLcontext *ctx)
                           save->FragmentProgramEnabled);
          _mesa_reference_fragprog(ctx, &ctx->FragmentProgram.Current,
                                   save->FragmentProgram);
+        _mesa_reference_fragprog(ctx, &save->FragmentProgram, NULL);
       }
 
       if (ctx->Extensions.ARB_shader_objects) {
@@ -720,6 +724,7 @@ _mesa_meta_end(GLcontext *ctx)
       for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
          _mesa_reference_texobj(&ctx->Texture.Unit[0].CurrentTex[tgt],
                                 save->CurrentTexture[tgt]);
+         _mesa_reference_texobj(&save->CurrentTexture[tgt], NULL);
       }
 
       /* Re-enable textures, texgen */