From 422ad2a6c9a2dc085d5b2b7d5cde85d92fab5b56 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 1 Dec 2021 07:51:38 +0900 Subject: [PATCH] [vulkan] Recreate lighting pvs sets when loading lights Sets never shrink, so assigning a dynamically created set to a statically created set after the working size has reduced (going from demo2 to demo3) causes the set code to attempt to resize the statically created set, which leads to libc having a bad time. --- libs/video/renderer/vulkan/vulkan_lighting.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libs/video/renderer/vulkan/vulkan_lighting.c b/libs/video/renderer/vulkan/vulkan_lighting.c index d2fcd5f5a..7ceb025e5 100644 --- a/libs/video/renderer/vulkan/vulkan_lighting.c +++ b/libs/video/renderer/vulkan/vulkan_lighting.c @@ -308,8 +308,6 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx) DARRAY_RESIZE (&lctx->frames, frames); lctx->frames.grow = 0; - lctx->sun_pvs = set_new (); - lctx->pipeline = Vulkan_CreatePipeline (ctx, "lighting"); lctx->layout = Vulkan_CreatePipelineLayout (ctx, "lighting_layout"); lctx->sampler = Vulkan_CreateSampler (ctx, "shadow_sampler"); @@ -373,9 +371,8 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx) shadow_set->a[i], va (ctx->va_ctx, "lighting:shadow_set:%zd", i)); - lframe->pvs = set_new (); - DARRAY_INIT (&lframe->lightvis, 16); + lframe->pvs = 0; lframe->leaf = 0; QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1, cmdSet); @@ -923,6 +920,17 @@ Vulkan_LoadLights (model_t *model, const char *entity_data, vulkan_ctx_t *ctx) lctx->lights.size = 0; lctx->lightleafs.size = 0; lctx->lightmats.size = 0; + if (lctx->sun_pvs) { + set_delete (lctx->sun_pvs); + } + lctx->sun_pvs = set_new_size (model->brush.visleafs); + for (size_t i = 0; i < ctx->frames.size; i++) { + __auto_type lframe = &lctx->frames.a[i]; + if (lframe->pvs) { + set_delete (lframe->pvs); + } + lframe->pvs = set_new_size (model->brush.visleafs); + } clear_shadows (ctx);