gallium: add some checks for null surface pointers in state tracker

Fixes some segfaults in low memory situations.
This commit is contained in:
Brian Paul
2008-10-18 09:55:54 -06:00
parent d422c1eb5c
commit 6c6c2f1d23
3 changed files with 25 additions and 12 deletions

View File

@@ -118,11 +118,12 @@ update_framebuffer_state( struct st_context *st )
update_renderbuffer_surface(st, strb); update_renderbuffer_surface(st, strb);
} }
assert(strb->surface); if (strb->surface) {
framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface; framebuffer->cbufs[framebuffer->num_cbufs] = strb->surface;
framebuffer->num_cbufs++; framebuffer->num_cbufs++;
} }
} }
}
strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer); strb = st_renderbuffer(fb->Attachment[BUFFER_DEPTH].Renderbuffer);
if (strb) { if (strb) {
@@ -132,7 +133,6 @@ update_framebuffer_state( struct st_context *st )
update_renderbuffer_surface(st, strb); update_renderbuffer_surface(st, strb);
} }
assert(strb->surface);
framebuffer->zsbuf = strb->surface; framebuffer->zsbuf = strb->surface;
} }
else { else {

View File

@@ -406,13 +406,17 @@ check_clear_stencil_with_quad(GLcontext *ctx, struct gl_renderbuffer *rb)
static void static void
clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{ {
struct st_renderbuffer *strb = st_renderbuffer(rb);
if (!strb->surface)
return;
if (check_clear_color_with_quad( ctx, rb )) { if (check_clear_color_with_quad( ctx, rb )) {
/* masking or scissoring */ /* masking or scissoring */
clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE); clear_with_quad(ctx, GL_TRUE, GL_FALSE, GL_FALSE);
} }
else { else {
/* clear whole buffer w/out masking */ /* clear whole buffer w/out masking */
struct st_renderbuffer *strb = st_renderbuffer(rb);
uint clearValue; uint clearValue;
/* NOTE: we always pass the clear color as PIPE_FORMAT_A8R8G8B8_UNORM /* NOTE: we always pass the clear color as PIPE_FORMAT_A8R8G8B8_UNORM
* at this time! * at this time!
@@ -426,13 +430,16 @@ clear_color_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
static void static void
clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{ {
struct st_renderbuffer *strb = st_renderbuffer(rb);
if (!strb->surface)
return;
if (check_clear_depth_with_quad(ctx, rb)) { if (check_clear_depth_with_quad(ctx, rb)) {
/* scissoring or we have a combined depth/stencil buffer */ /* scissoring or we have a combined depth/stencil buffer */
clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE); clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE);
} }
else { else {
struct st_renderbuffer *strb = st_renderbuffer(rb);
/* simple clear of whole buffer */ /* simple clear of whole buffer */
uint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear); uint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear);
ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue); ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
@@ -443,13 +450,16 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
static void static void
clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{ {
struct st_renderbuffer *strb = st_renderbuffer(rb);
if (!strb->surface)
return;
if (check_clear_stencil_with_quad(ctx, rb)) { if (check_clear_stencil_with_quad(ctx, rb)) {
/* masking or scissoring or combined depth/stencil buffer */ /* masking or scissoring or combined depth/stencil buffer */
clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE); clear_with_quad(ctx, GL_FALSE, GL_FALSE, GL_TRUE);
} }
else { else {
struct st_renderbuffer *strb = st_renderbuffer(rb);
/* simple clear of whole buffer */ /* simple clear of whole buffer */
GLuint clearValue = ctx->Stencil.Clear; GLuint clearValue = ctx->Stencil.Clear;
@@ -469,14 +479,16 @@ clear_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
static void static void
clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) clear_depth_stencil_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
{ {
struct st_renderbuffer *strb = st_renderbuffer(rb);
if (!strb->surface)
return;
if (check_clear_depth_stencil_with_quad(ctx, rb)) { if (check_clear_depth_stencil_with_quad(ctx, rb)) {
/* masking or scissoring */ /* masking or scissoring */
clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE); clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_TRUE);
} }
else { else {
struct st_renderbuffer *strb = st_renderbuffer(rb);
/* clear whole buffer w/out masking */ /* clear whole buffer w/out masking */
GLuint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear); GLuint clearValue = util_pack_z(strb->surface->format, ctx->Depth.Clear);

View File

@@ -289,6 +289,7 @@ st_notify_swapbuffers_complete(struct st_framebuffer *stfb)
for (i = 0; i < BUFFER_COUNT; i++) { for (i = 0; i < BUFFER_COUNT; i++) {
if (stfb->Base.Attachment[i].Renderbuffer) { if (stfb->Base.Attachment[i].Renderbuffer) {
strb = st_renderbuffer(stfb->Base.Attachment[i].Renderbuffer); strb = st_renderbuffer(stfb->Base.Attachment[i].Renderbuffer);
if (strb->surface)
strb->surface->status = PIPE_SURFACE_STATUS_UNDEFINED; strb->surface->status = PIPE_SURFACE_STATUS_UNDEFINED;
} }
} }