renderer: switch to context 0 before destroy sub

If the current context is one of the subcontext to be destroyed,
vrend_destroy_sub_context() will fail after the last context is
destroyed.

Found thanks to amaerican fuzzy lop.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
macos/master
Marc-André Lureau 9 years ago committed by Dave Airlie
parent a342dc9149
commit e9e19b5b47
  1. 5
      src/vrend_renderer.c

@ -3870,6 +3870,7 @@ static void vrend_destroy_sub_context(struct vrend_sub_context *sub)
bool vrend_destroy_context(struct vrend_context *ctx) bool vrend_destroy_context(struct vrend_context *ctx)
{ {
bool switch_0 = (ctx == vrend_state.current_ctx); bool switch_0 = (ctx == vrend_state.current_ctx);
struct vrend_context *cur = vrend_state.current_ctx;
struct vrend_sub_context *sub, *tmp; struct vrend_sub_context *sub, *tmp;
if (switch_0) { if (switch_0) {
vrend_state.current_ctx = NULL; vrend_state.current_ctx = NULL;
@ -3893,6 +3894,7 @@ bool vrend_destroy_context(struct vrend_context *ctx)
vrend_set_index_buffer(ctx, 0, 0, 0); vrend_set_index_buffer(ctx, 0, 0, 0);
vrend_renderer_force_ctx_0();
LIST_FOR_EACH_ENTRY_SAFE(sub, tmp, &ctx->sub_ctxs, head) LIST_FOR_EACH_ENTRY_SAFE(sub, tmp, &ctx->sub_ctxs, head)
vrend_destroy_sub_context(sub); vrend_destroy_sub_context(sub);
@ -3902,6 +3904,9 @@ bool vrend_destroy_context(struct vrend_context *ctx)
FREE(ctx); FREE(ctx);
if (!switch_0 && cur)
vrend_hw_switch_context(cur, true);
return switch_0; return switch_0;
} }

Loading…
Cancel
Save