Fix a pile of leaks and uninit errors

Still "some" more to go: a pile to do with transforms and temporary
entities, and a nasty one with host_cbuf. There's also all the static
block-alloc lists :/
This commit is contained in:
Bill Currie 2021-03-21 19:56:17 +09:00
parent a3c1b2e992
commit cc4167668c
16 changed files with 153 additions and 81 deletions

View file

@ -70,7 +70,7 @@ typedef struct lightingframe_s {
// illuminate the leafs visible to the player // illuminate the leafs visible to the player
byte pvs[MAP_PVS_BYTES]; byte pvs[MAP_PVS_BYTES];
struct mleaf_s *leaf; // the last leaf used to generate the pvs struct mleaf_s *leaf; // the last leaf used to generate the pvs
qfv_lightleafset_t lightvis; qfv_lightvisset_t lightvis;
} lightingframe_t; } lightingframe_t;
typedef struct lightingframeset_s typedef struct lightingframeset_s

View file

@ -1782,6 +1782,7 @@ struct progs_s {
///@{ ///@{
struct hashtab_s *builtin_hash; struct hashtab_s *builtin_hash;
struct hashtab_s *builtin_num_hash; struct hashtab_s *builtin_num_hash;
struct biblock_s *builtin_blocks;
unsigned bi_next; unsigned bi_next;
unsigned (*bi_map) (progs_t *pr, unsigned binum); unsigned (*bi_map) (progs_t *pr, unsigned binum);
///@} ///@}

View file

@ -172,6 +172,7 @@ Load_Tracklist (void)
buffile = calloc (size+10, sizeof (char)); buffile = calloc (size+10, sizeof (char));
Qread (oggfile, buffile, size); Qread (oggfile, buffile, size);
PL_Free (tracklist);
tracklist = PL_GetPropertyList (buffile, 0); tracklist = PL_GetPropertyList (buffile, 0);
if (!tracklist || PL_Type (tracklist) != QFDictionary) { if (!tracklist || PL_Type (tracklist) != QFDictionary) {
Sys_Printf ("Malformed or empty tracklist file. check mus_ogglist\n"); Sys_Printf ("Malformed or empty tracklist file. check mus_ogglist\n");

View file

@ -249,6 +249,7 @@ vorbis_stream_close (sfx_t *sfx)
if (vf->data) if (vf->data)
free (vf->data); free (vf->data);
ov_clear (vf->vf); ov_clear (vf->vf);
free (vf->vf);
free (vf); free (vf);
SND_SFX_StreamClose (sfx); SND_SFX_StreamClose (sfx);
} }

View file

@ -317,12 +317,13 @@ CL_ParseBeam (qmsg_t *net_message, model_t *m, double time, TEntContext_t *ctx)
tent_obj_t *to; tent_obj_t *to;
beam_t *b; beam_t *b;
int ent; int ent;
vec3_t start, end; vec4f_t start, end;
ent = MSG_ReadShort (net_message); ent = MSG_ReadShort (net_message);
MSG_ReadCoordV (net_message, start); MSG_ReadCoordV (net_message, &start[0]);//FIXME
MSG_ReadCoordV (net_message, end); MSG_ReadCoordV (net_message, &end[0]);//FIXME
start[3] = end[3] = 1;//FIXME
to = 0; to = 0;
if (ent) { if (ent) {
@ -345,10 +346,10 @@ CL_ParseBeam (qmsg_t *net_message, model_t *m, double time, TEntContext_t *ctx)
b->model = m; b->model = m;
b->endtime = time + 0.2; b->endtime = time + 0.2;
b->seed = rand (); b->seed = rand ();
VectorCopy (end, b->end); b->end = end;
if (b->entity != ctx->playerEntity) { if (b->entity != ctx->playerEntity) {
// this will be done in CL_UpdateBeams // this will be done in CL_UpdateBeams
VectorCopy (start, b->start); b->start = start;
beam_setup (b, true, time, ctx); beam_setup (b, true, time, ctx);
} }
} }
@ -626,7 +627,7 @@ CL_UpdateBeams (double time, TEntContext_t *ctx)
// if coming from the player, update the start position // if coming from the player, update the start position
if (b->entity == ctx->playerEntity) { if (b->entity == ctx->playerEntity) {
beam_clear (b); beam_clear (b);
VectorCopy (ctx->simorg, b->start); b->start = ctx->simorg;
beam_setup (b, false, time, ctx); beam_setup (b, false, time, ctx);
} }

View file

@ -40,6 +40,7 @@
#include "QF/cmd.h" #include "QF/cmd.h"
#include "QF/crc.h" #include "QF/crc.h"
#include "QF/cvar.h" #include "QF/cvar.h"
#include "QF/darray.h"
#include "QF/hash.h" #include "QF/hash.h"
#include "QF/progs.h" #include "QF/progs.h"
#include "QF/qdefs.h" #include "QF/qdefs.h"
@ -50,6 +51,8 @@
#include "compat.h" #include "compat.h"
typedef struct biblock_s DARRAY_TYPE (builtin_t *) biblock_t;
static const char * static const char *
builtin_get_key (const void *_bi, void *unused) builtin_get_key (const void *_bi, void *unused)
{ {
@ -92,6 +95,8 @@ PR_RegisterBuiltins (progs_t *pr, builtin_t *builtins)
int count; int count;
if (!pr->builtin_hash) { if (!pr->builtin_hash) {
pr->builtin_blocks = malloc (sizeof (biblock_t));
DARRAY_INIT (pr->builtin_blocks, 16);
pr->builtin_hash = Hash_NewTable (1021, builtin_get_key, 0, pr, pr->builtin_hash = Hash_NewTable (1021, builtin_get_key, 0, pr,
pr->hashlink_freelist); pr->hashlink_freelist);
pr->builtin_num_hash = Hash_NewTable (1021, 0, 0, pr, pr->builtin_num_hash = Hash_NewTable (1021, 0, 0, pr,
@ -104,6 +109,7 @@ PR_RegisterBuiltins (progs_t *pr, builtin_t *builtins)
for (bi = builtins, count = 1; bi->name; bi++) for (bi = builtins, count = 1; bi->name; bi++)
count++; count++;
bi = malloc (count * sizeof (builtin_t)); bi = malloc (count * sizeof (builtin_t));
DARRAY_APPEND (pr->builtin_blocks, bi);
memcpy (bi, builtins, count * sizeof (builtin_t)); memcpy (bi, builtins, count * sizeof (builtin_t));
builtins = bi; builtins = bi;

View file

@ -387,4 +387,7 @@ Mod_LoadAliasModel (model_t *mod, void *buffer, cache_allocator_t allocator)
} else { } else {
mod->aliashdr = header; mod->aliashdr = header;
} }
DARRAY_CLEAR (&alias_ctx.poseverts);
DARRAY_CLEAR (&alias_ctx.stverts);
DARRAY_CLEAR (&alias_ctx.triangles);
} }

View file

@ -326,6 +326,7 @@ load_textures (model_t *mod, vulkan_ctx_t *ctx)
barriers->size, barriers->a); barriers->size, barriers->a);
QFV_PacketSubmit (packet); QFV_PacketSubmit (packet);
QFV_DestroyStagingBuffer (stage); QFV_DestroyStagingBuffer (stage);
free (barriers);
} }
void void

View file

@ -223,6 +223,7 @@ PL_Free (plitem_t *item)
dict = item->data; dict = item->data;
Hash_DelTable (dict->tab); Hash_DelTable (dict->tab);
DARRAY_CLEAR (&dict->keys); DARRAY_CLEAR (&dict->keys);
free (item->data);
break; break;
case QFArray: case QFArray:

View file

@ -252,12 +252,11 @@ static void
delete_searchpath (searchpath_t *searchpath) delete_searchpath (searchpath_t *searchpath)
{ {
if (searchpath->pack) { if (searchpath->pack) {
Qclose (searchpath->pack->handle); pack_del (searchpath->pack);
free (searchpath->pack->files);
free (searchpath->pack);
} }
if (searchpath->filename) if (searchpath->filename) {
free (searchpath->filename); free (searchpath->filename);
}
FREE (searchpaths, searchpath); FREE (searchpaths, searchpath);
} }
@ -274,8 +273,9 @@ delete_vpath (vpath_t *vpath)
{ {
searchpath_t *next; searchpath_t *next;
if (vpath->name) if (vpath->name) {
free (vpath->name); free (vpath->name);
}
while (vpath->user) { while (vpath->user) {
next = vpath->user->next; next = vpath->user->next;
delete_searchpath (vpath->user); delete_searchpath (vpath->user);
@ -859,6 +859,7 @@ qfs_findfile_search (const vpath_t *vpath, const searchpath_t *sp,
found.ff.realname = strdup (*fn); found.ff.realname = strdup (*fn);
found.path = strdup (path->str); found.path = strdup (path->str);
found.fname_index = fn - fnames; found.fname_index = fn - fnames;
dstring_delete (path);
return &found; return &found;
} }
} }
@ -1416,6 +1417,16 @@ qfs_path_cvar (cvar_t *var)
free (cpath); free (cpath);
} }
static void
qfs_shutdown (void *data)
{
while (qfs_vpaths) {
vpath_t *next = qfs_vpaths->next;
delete_vpath (qfs_vpaths);
qfs_vpaths = next;
}
}
VISIBLE void VISIBLE void
QFS_Init (const char *game) QFS_Init (const char *game)
{ {
@ -1465,6 +1476,7 @@ QFS_Init (const char *game)
} else { } else {
QFS_Gamedir (""); QFS_Gamedir ("");
} }
Sys_RegisterShutdown (qfs_shutdown, 0);
} }
VISIBLE const char * VISIBLE const char *

View file

@ -285,11 +285,14 @@ void
QFV_DestroyInstance (qfv_instance_t *instance) QFV_DestroyInstance (qfv_instance_t *instance)
{ {
qfv_instfuncs_t *ifunc = instance->funcs; qfv_instfuncs_t *ifunc = instance->funcs;
if (instance->debug_handle) { if (instance->debug_handle) {
ifunc->vkDestroyDebugUtilsMessengerEXT (instance->instance, ifunc->vkDestroyDebugUtilsMessengerEXT (instance->instance,
instance->debug_handle, 0); instance->debug_handle, 0);
} }
instance->funcs->vkDestroyInstance (instance->instance, 0); instance->funcs->vkDestroyInstance (instance->instance, 0);
del_strset (instance->enabled_extensions);
free (instance->devices);
free (instance); free (instance);
} }

View file

@ -252,6 +252,13 @@ parse_reference (const plitem_t *item, const char *type, plitem_t *messages,
return refItem; return refItem;
} }
static void *
vkparse_alloc (void *context, size_t size)
{
parsectx_t *pctx = context;
return cmemalloc (pctx->ectx->memsuper, size);
}
static int static int
parse_single (const plfield_t *field, const plitem_t *item, parse_single (const plfield_t *field, const plitem_t *item,
void *data, plitem_t *messages, void *context) void *data, plitem_t *messages, void *context)
@ -269,9 +276,9 @@ parse_single (const plfield_t *field, const plitem_t *item,
} }
plfield_t f = { 0, 0, single->type, single->parser, 0 }; plfield_t f = { 0, 0, single->type, single->parser, 0 };
void *value = calloc (1, single->stride); void *value = vkparse_alloc (context, single->stride);
memset (value, 0, single->stride);
if (!single->parser (&f, item, value, messages, context)) { if (!single->parser (&f, item, value, messages, context)) {
free (value);
return 0; return 0;
} }
@ -279,12 +286,6 @@ parse_single (const plfield_t *field, const plitem_t *item,
return 1; return 1;
} }
static void *
array_alloc (void *context, size_t size)
{
return malloc (size);
}
static int static int
parse_array (const plfield_t *field, const plitem_t *item, parse_array (const plfield_t *field, const plitem_t *item,
void *data, plitem_t *messages, void *context) void *data, plitem_t *messages, void *context)
@ -296,7 +297,7 @@ parse_array (const plfield_t *field, const plitem_t *item,
plelement_t element = { plelement_t element = {
array->type, array->type,
array->stride, array->stride,
array_alloc, vkparse_alloc,
array->parser, array->parser,
0, 0,
}; };
@ -313,12 +314,11 @@ parse_array (const plfield_t *field, const plitem_t *item,
if (!PL_ParseArray (&f, item, &arr, messages, context)) { if (!PL_ParseArray (&f, item, &arr, messages, context)) {
return 0; return 0;
} }
*value = malloc (array->stride * arr->size); *value = vkparse_alloc (context, array->stride * arr->size);
memcpy (*value, arr->a, array->stride * arr->size); memcpy (*value, arr->a, array->stride * arr->size);
if ((void *) size >= data) { if ((void *) size >= data) {
*size = arr->size; *size = arr->size;
} }
free (arr);
return 1; return 1;
} }
@ -339,7 +339,7 @@ parse_data (const plfield_t *field, const plitem_t *item,
Sys_Printf (" %zd %zd\n", datad->value_offset, datad->size_offset); Sys_Printf (" %zd %zd\n", datad->value_offset, datad->size_offset);
Sys_Printf (" %zd %p\n", binsize, bindata); Sys_Printf (" %zd %p\n", binsize, bindata);
*value = malloc (binsize); *value = vkparse_alloc (context, binsize);
memcpy (*value, bindata, binsize); memcpy (*value, bindata, binsize);
if ((void *) size > data) { if ((void *) size > data) {
*size = binsize; *size = binsize;
@ -362,7 +362,9 @@ parse_string (const plfield_t *field, const plitem_t *item,
//Sys_Printf (" %zd\n", string->value_offset); //Sys_Printf (" %zd\n", string->value_offset);
//Sys_Printf (" %s\n", str); //Sys_Printf (" %s\n", str);
*value = strdup (str); size_t len = strlen (str) + 1;
*value = vkparse_alloc (context, len);
memcpy (*value, str, len);
return 1; return 1;
} }
@ -877,7 +879,7 @@ typedef struct qfv_renderpass_s {
static plelement_t parse_qfv_renderpass_attachments_data = { static plelement_t parse_qfv_renderpass_attachments_data = {
QFDictionary, QFDictionary,
sizeof (VkAttachmentDescription), sizeof (VkAttachmentDescription),
array_alloc, vkparse_alloc,
parse_VkAttachmentDescription, parse_VkAttachmentDescription,
0, 0,
}; };
@ -885,7 +887,7 @@ static plelement_t parse_qfv_renderpass_attachments_data = {
static plelement_t parse_qfv_renderpass_subpasses_data = { static plelement_t parse_qfv_renderpass_subpasses_data = {
QFDictionary, QFDictionary,
sizeof (VkSubpassDescription), sizeof (VkSubpassDescription),
array_alloc, vkparse_alloc,
parse_VkSubpassDescription, parse_VkSubpassDescription,
0, 0,
}; };
@ -893,7 +895,7 @@ static plelement_t parse_qfv_renderpass_subpasses_data = {
static plelement_t parse_qfv_renderpass_dependencies_data = { static plelement_t parse_qfv_renderpass_dependencies_data = {
QFDictionary, QFDictionary,
sizeof (VkSubpassDependency), sizeof (VkSubpassDependency),
array_alloc, vkparse_alloc,
parse_VkSubpassDependency, parse_VkSubpassDependency,
0, 0,
}; };
@ -953,7 +955,7 @@ QFV_GetEnum (const char *name)
} }
static int static int
parse_object (vulkan_ctx_t *ctx, plitem_t *plist, parse_object (vulkan_ctx_t *ctx, memsuper_t *memsuper, plitem_t *plist,
plparser_t parser, void *object, plitem_t *properties) plparser_t parser, void *object, plitem_t *properties)
{ {
plitem_t *messages = PL_NewArray (); plitem_t *messages = PL_NewArray ();
@ -970,9 +972,9 @@ parse_object (vulkan_ctx_t *ctx, plitem_t *plist,
exprtab_t vars_tab = { var_syms, 0 }; exprtab_t vars_tab = { var_syms, 0 };
exprctx.external_variables = &vars_tab; exprctx.external_variables = &vars_tab;
exprctx.memsuper = new_memsuper ();
exprctx.messages = messages; exprctx.messages = messages;
exprctx.hashlinks = &ctx->hashlinks; exprctx.hashlinks = &ctx->hashlinks;
exprctx.memsuper = memsuper;
cexpr_init_symtab (&vars_tab, &exprctx); cexpr_init_symtab (&vars_tab, &exprctx);
@ -983,8 +985,8 @@ parse_object (vulkan_ctx_t *ctx, plitem_t *plist,
} }
return 0; return 0;
} }
Hash_DelTable (vars_tab.tab);
PL_Free (messages); PL_Free (messages);
delete_memsuper (exprctx.memsuper);
return 1; return 1;
} }
@ -999,12 +1001,14 @@ parse_qfv_renderpass (const plfield_t *field, const plitem_t *item, void *data,
VkRenderPass VkRenderPass
QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties) QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
{ {
memsuper_t *memsuper = new_memsuper ();
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_renderpass_t renderpass_data = {}; qfv_renderpass_t renderpass_data = {};
if (!parse_object (ctx, plist, parse_qfv_renderpass, &renderpass_data, if (!parse_object (ctx, memsuper, plist, parse_qfv_renderpass,
properties)) { &renderpass_data, properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
@ -1014,29 +1018,22 @@ QFV_ParseRenderPass (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
renderpass_data.subpasses, renderpass_data.subpasses,
renderpass_data.dependencies); renderpass_data.dependencies);
free (renderpass_data.attachments); delete_memsuper (memsuper);
for (size_t i = 0; i < renderpass_data.subpasses->size; i++) {
free ((void *) renderpass_data.subpasses->a[i].pInputAttachments);
free ((void *) renderpass_data.subpasses->a[i].pColorAttachments);
free ((void *) renderpass_data.subpasses->a[i].pResolveAttachments);
free ((void *) renderpass_data.subpasses->a[i].pDepthStencilAttachment);
free ((void *) renderpass_data.subpasses->a[i].pPreserveAttachments);
}
free (renderpass_data.subpasses);
free (renderpass_data.dependencies);
return renderpass; return renderpass;
} }
VkPipeline VkPipeline
QFV_ParsePipeline (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties) QFV_ParsePipeline (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
{ {
memsuper_t *memsuper = new_memsuper ();
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
__auto_type cInfo = QFV_AllocGraphicsPipelineCreateInfoSet (1, alloca); __auto_type cInfo = QFV_AllocGraphicsPipelineCreateInfoSet (1, alloca);
memset (&cInfo->a[0], 0, sizeof (cInfo->a[0])); memset (&cInfo->a[0], 0, sizeof (cInfo->a[0]));
if (!parse_object (ctx, plist, parse_VkGraphicsPipelineCreateInfo, if (!parse_object (ctx, memsuper, plist, parse_VkGraphicsPipelineCreateInfo,
&cInfo->a[0], properties)) { &cInfo->a[0], properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
@ -1044,6 +1041,7 @@ QFV_ParsePipeline (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
__auto_type plSet = QFV_CreateGraphicsPipelines (device, 0, cInfo); __auto_type plSet = QFV_CreateGraphicsPipelines (device, 0, cInfo);
VkPipeline pipeline = plSet->a[0]; VkPipeline pipeline = plSet->a[0];
free (plSet); free (plSet);
delete_memsuper (memsuper);
return pipeline; return pipeline;
} }
@ -1053,17 +1051,20 @@ QFV_ParseDescriptorPool (vulkan_ctx_t *ctx, plitem_t *plist,
{ {
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
memsuper_t *memsuper = new_memsuper ();
VkDescriptorPoolCreateInfo cInfo = {}; VkDescriptorPoolCreateInfo cInfo = {};
if (!parse_object (ctx, plist, parse_VkDescriptorPoolCreateInfo, &cInfo, if (!parse_object (ctx, memsuper, plist, parse_VkDescriptorPoolCreateInfo,
properties)) { &cInfo, properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
VkDescriptorPool pool; VkDescriptorPool pool;
dfunc->vkCreateDescriptorPool (device->dev, &cInfo, 0, &pool); dfunc->vkCreateDescriptorPool (device->dev, &cInfo, 0, &pool);
delete_memsuper (memsuper);
return pool; return pool;
} }
@ -1073,17 +1074,21 @@ QFV_ParseDescriptorSetLayout (vulkan_ctx_t *ctx, plitem_t *plist,
{ {
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
memsuper_t *memsuper = new_memsuper ();
VkDescriptorSetLayoutCreateInfo cInfo = {}; VkDescriptorSetLayoutCreateInfo cInfo = {};
if (!parse_object (ctx, plist, parse_VkDescriptorSetLayoutCreateInfo, if (!parse_object (ctx, memsuper, plist,
parse_VkDescriptorSetLayoutCreateInfo,
&cInfo, properties)) { &cInfo, properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
VkDescriptorSetLayout setLayout; VkDescriptorSetLayout setLayout;
dfunc->vkCreateDescriptorSetLayout (device->dev, &cInfo, 0, &setLayout); dfunc->vkCreateDescriptorSetLayout (device->dev, &cInfo, 0, &setLayout);
delete_memsuper (memsuper);
return setLayout; return setLayout;
} }
@ -1093,17 +1098,20 @@ QFV_ParsePipelineLayout (vulkan_ctx_t *ctx, plitem_t *plist,
{ {
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
memsuper_t *memsuper = new_memsuper ();
VkPipelineLayoutCreateInfo cInfo = {}; VkPipelineLayoutCreateInfo cInfo = {};
if (!parse_object (ctx, plist, parse_VkPipelineLayoutCreateInfo, if (!parse_object (ctx, memsuper, plist, parse_VkPipelineLayoutCreateInfo,
&cInfo, properties)) { &cInfo, properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
VkPipelineLayout layout; VkPipelineLayout layout;
dfunc->vkCreatePipelineLayout (device->dev, &cInfo, 0, &layout); dfunc->vkCreatePipelineLayout (device->dev, &cInfo, 0, &layout);
delete_memsuper (memsuper);
return layout; return layout;
} }
@ -1112,17 +1120,20 @@ QFV_ParseSampler (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
{ {
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
memsuper_t *memsuper = new_memsuper ();
VkSamplerCreateInfo cInfo = {}; VkSamplerCreateInfo cInfo = {};
if (!parse_object (ctx, plist, parse_VkSamplerCreateInfo, &cInfo, if (!parse_object (ctx, memsuper, plist, parse_VkSamplerCreateInfo, &cInfo,
properties)) { properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
VkSampler sampler; VkSampler sampler;
dfunc->vkCreateSampler (device->dev, &cInfo, 0, &sampler); dfunc->vkCreateSampler (device->dev, &cInfo, 0, &sampler);
delete_memsuper (memsuper);
return sampler; return sampler;
} }
@ -1131,17 +1142,20 @@ QFV_ParseImage (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
{ {
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
memsuper_t *memsuper = new_memsuper ();
VkImageCreateInfo cInfo = {}; VkImageCreateInfo cInfo = {};
if (!parse_object (ctx, plist, parse_VkImageCreateInfo, &cInfo, if (!parse_object (ctx, memsuper, plist, parse_VkImageCreateInfo, &cInfo,
properties)) { properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
VkImage image; VkImage image;
dfunc->vkCreateImage (device->dev, &cInfo, 0, &image); dfunc->vkCreateImage (device->dev, &cInfo, 0, &image);
delete_memsuper (memsuper);
return image; return image;
} }
@ -1150,17 +1164,20 @@ QFV_ParseImageView (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
{ {
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
memsuper_t *memsuper = new_memsuper ();
VkImageViewCreateInfo cInfo = {}; VkImageViewCreateInfo cInfo = {};
if (!parse_object (ctx, plist, parse_VkImageViewCreateInfo, &cInfo, if (!parse_object (ctx, memsuper, plist, parse_VkImageViewCreateInfo,
properties)) { &cInfo, properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
VkImageView imageView; VkImageView imageView;
dfunc->vkCreateImageView (device->dev, &cInfo, 0, &imageView); dfunc->vkCreateImageView (device->dev, &cInfo, 0, &imageView);
delete_memsuper (memsuper);
return imageView; return imageView;
} }
@ -1177,14 +1194,14 @@ typedef struct {
static plelement_t qfv_imagecreate_dict = { static plelement_t qfv_imagecreate_dict = {
QFDictionary, QFDictionary,
sizeof (VkImageCreateInfo), sizeof (VkImageCreateInfo),
array_alloc, vkparse_alloc,
parse_VkImageCreateInfo, parse_VkImageCreateInfo,
}; };
static plelement_t qfv_imageviewcreate_dict = { static plelement_t qfv_imageviewcreate_dict = {
QFDictionary, QFDictionary,
sizeof (VkImageViewCreateInfo), sizeof (VkImageViewCreateInfo),
array_alloc, vkparse_alloc,
parse_VkImageViewCreateInfo, parse_VkImageViewCreateInfo,
}; };
@ -1202,11 +1219,6 @@ parse_imagecreate_dict (const plfield_t *field, const plitem_t *item,
imagecreate_t *imagecreate = data; imagecreate_t *imagecreate = data;
imagecreate->count = arr->size; imagecreate->count = arr->size;
imagecreate->info = (VkImageCreateInfo *) arr->a; imagecreate->info = (VkImageCreateInfo *) arr->a;
} else {
//FIXME leaky boat when succeeds
if (arr) {
free (arr);
}
} }
return ret; return ret;
} }
@ -1239,18 +1251,21 @@ QFV_ParseImageSet (vulkan_ctx_t *ctx, plitem_t *item, plitem_t *properties)
{ {
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
memsuper_t *memsuper = new_memsuper ();
imagecreate_t create = {}; imagecreate_t create = {};
pltype_t type = PL_Type (item); pltype_t type = PL_Type (item);
if (type == QFDictionary) { if (type == QFDictionary) {
if (!parse_object (ctx, item, parse_imagecreate_dict, &create, if (!parse_object (ctx, memsuper, item, parse_imagecreate_dict,
properties)) { &create, properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
} else { } else {
Sys_Printf ("Neither array nor dictionary: %d\n", PL_Line (item)); Sys_Printf ("Neither array nor dictionary: %d\n", PL_Line (item));
delete_memsuper (memsuper);
return 0; return 0;
} }
@ -1265,6 +1280,7 @@ QFV_ParseImageSet (vulkan_ctx_t *ctx, plitem_t *item, plitem_t *properties)
QFV_AddHandle (ctx->images, name, (uint64_t) set->a[i]); QFV_AddHandle (ctx->images, name, (uint64_t) set->a[i]);
} }
delete_memsuper (memsuper);
return set; return set;
} }
@ -1274,18 +1290,21 @@ QFV_ParseImageViewSet (vulkan_ctx_t *ctx, plitem_t *item,
{ {
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
memsuper_t *memsuper = new_memsuper ();
imageviewcreate_t create = {}; imageviewcreate_t create = {};
pltype_t type = PL_Type (item); pltype_t type = PL_Type (item);
if (type == QFDictionary) { if (type == QFDictionary) {
if (!parse_object (ctx, item, parse_imageviewcreate_dict, &create, if (!parse_object (ctx, memsuper, item, parse_imageviewcreate_dict,
properties)) { &create, properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
} else { } else {
Sys_Printf ("Neither array nor dictionary: %d\n", PL_Line (item)); Sys_Printf ("Neither array nor dictionary: %d\n", PL_Line (item));
delete_memsuper (memsuper);
return 0; return 0;
} }
@ -1298,6 +1317,7 @@ QFV_ParseImageViewSet (vulkan_ctx_t *ctx, plitem_t *item,
QFV_AddHandle (ctx->imageViews, name, (uint64_t) set->a[i]); QFV_AddHandle (ctx->imageViews, name, (uint64_t) set->a[i]);
} }
delete_memsuper (memsuper);
return set; return set;
} }
@ -1306,11 +1326,13 @@ QFV_ParseFramebuffer (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
{ {
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
memsuper_t *memsuper = new_memsuper ();
VkFramebufferCreateInfo cInfo = {}; VkFramebufferCreateInfo cInfo = {};
if (!parse_object (ctx, plist, parse_VkFramebufferCreateInfo, &cInfo, if (!parse_object (ctx, memsuper, plist, parse_VkFramebufferCreateInfo,
properties)) { &cInfo, properties)) {
delete_memsuper (memsuper);
return 0; return 0;
} }
@ -1318,6 +1340,7 @@ QFV_ParseFramebuffer (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
dfunc->vkCreateFramebuffer (device->dev, &cInfo, 0, &framebuffer); dfunc->vkCreateFramebuffer (device->dev, &cInfo, 0, &framebuffer);
printf ("framebuffer, renderPass: %p, %p\n", framebuffer, cInfo.renderPass); printf ("framebuffer, renderPass: %p, %p\n", framebuffer, cInfo.renderPass);
delete_memsuper (memsuper);
return framebuffer; return framebuffer;
} }
@ -1325,19 +1348,16 @@ static int
parse_clearvalueset (const plfield_t *field, const plitem_t *item, void *data, parse_clearvalueset (const plfield_t *field, const plitem_t *item, void *data,
plitem_t *messages, void *context) plitem_t *messages, void *context)
{ {
parsectx_t *parsectx = context;
vulkan_ctx_t *ctx = parsectx->vctx;
plelement_t element = { plelement_t element = {
QFDictionary, QFDictionary,
sizeof (VkClearValue), sizeof (VkClearValue),
array_alloc, vkparse_alloc,
parse_VkClearValue, parse_VkClearValue,
0, 0,
}; };
plfield_t f = { 0, 0, 0, 0, &element }; plfield_t f = { 0, 0, 0, 0, &element };
if (!PL_ParseArray (&f, item, &ctx->clearValues, messages, context)) { if (!PL_ParseArray (&f, item, data, messages, context)) {
return 0; return 0;
} }
return 1; return 1;
@ -1346,9 +1366,19 @@ parse_clearvalueset (const plfield_t *field, const plitem_t *item, void *data,
int int
QFV_ParseClearValues (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties) QFV_ParseClearValues (vulkan_ctx_t *ctx, plitem_t *plist, plitem_t *properties)
{ {
if (!parse_object (ctx, plist, parse_clearvalueset, &ctx->clearValues, int ret = 0;
properties)) { memsuper_t *memsuper = new_memsuper ();
return 0; clearvalueset_t *clearValues = 0;
ctx->clearValues = 0;
if (parse_object (ctx, memsuper, plist, parse_clearvalueset, &clearValues,
properties)) {
ret = 1;
ctx->clearValues = DARRAY_ALLOCFIXED (clearvalueset_t,
clearValues->size, malloc);
memcpy (ctx->clearValues->a, clearValues->a,
clearValues->size * sizeof (clearValues->a[0]));
} }
return 1; delete_memsuper (memsuper);
return ret;
} }

View file

@ -77,7 +77,7 @@ find_visible_lights (vulkan_ctx_t *ctx)
} }
if (leaf != lframe->leaf) { if (leaf != lframe->leaf) {
double start = Sys_DoubleTime (); //double start = Sys_DoubleTime ();
byte pvs[MAP_PVS_BYTES]; byte pvs[MAP_PVS_BYTES];
Mod_LeafPVS_set (leaf, model, 0, pvs); Mod_LeafPVS_set (leaf, model, 0, pvs);
@ -89,8 +89,8 @@ find_visible_lights (vulkan_ctx_t *ctx)
} }
lframe->leaf = leaf; lframe->leaf = leaf;
double end = Sys_DoubleTime (); //double end = Sys_DoubleTime ();
Sys_Printf ("find_visible_lights: %.5gus\n", (end - start) * 1e6); //Sys_Printf ("find_visible_lights: %.5gus\n", (end - start) * 1e6);
int visible = 0; int visible = 0;
memset (lframe->lightvis.a, 0, lframe->lightvis.size * sizeof (byte)); memset (lframe->lightvis.a, 0, lframe->lightvis.size * sizeof (byte));
@ -101,8 +101,8 @@ find_visible_lights (vulkan_ctx_t *ctx)
visible++; visible++;
} }
} }
Sys_Printf ("find_visible_lights: %d / %zd visible\n", visible, //Sys_Printf ("find_visible_lights: %d / %zd visible\n", visible,
lframe->lightvis.size); // lframe->lightvis.size);
} }
} }
@ -313,6 +313,7 @@ Vulkan_Lighting_Init (vulkan_ctx_t *ctx)
__auto_type lframe = &lctx->frames.a[i]; __auto_type lframe = &lctx->frames.a[i];
DARRAY_INIT (&lframe->lightvis, 16); DARRAY_INIT (&lframe->lightvis, 16);
lframe->leaf = 0;
QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1, cmdSet); QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1, cmdSet);
lframe->cmd = cmdSet->a[0]; lframe->cmd = cmdSet->a[0];

View file

@ -186,6 +186,8 @@ clear_table (hashtab_t **table)
void void
Vulkan_Shutdown_Common (vulkan_ctx_t *ctx) Vulkan_Shutdown_Common (vulkan_ctx_t *ctx)
{ {
PL_Free (ctx->pipelineDef);
PL_Free (ctx->renderpassDef);
if (ctx->pipeline) { if (ctx->pipeline) {
QFV_DestroyPipeline (ctx->device, ctx->pipeline); QFV_DestroyPipeline (ctx->device, ctx->pipeline);
} }
@ -546,6 +548,10 @@ Vulkan_DestroyFrames (vulkan_ctx_t *ctx)
df->vkDestroySemaphore (dev, frame->imageAvailableSemaphore, 0); df->vkDestroySemaphore (dev, frame->imageAvailableSemaphore, 0);
df->vkDestroySemaphore (dev, frame->renderDoneSemaphore, 0); df->vkDestroySemaphore (dev, frame->renderDoneSemaphore, 0);
df->vkDestroyFramebuffer (dev, frame->framebuffer, 0); df->vkDestroyFramebuffer (dev, frame->framebuffer, 0);
for (int j = 0; j < frame->cmdSetCount; j++) {
DARRAY_CLEAR (&frame->cmdSets[j]);
}
free (frame->cmdSets);
} }
DARRAY_CLEAR (&ctx->frames); DARRAY_CLEAR (&ctx->frames);

View file

@ -311,9 +311,9 @@ void
X11_CreateNullCursor (void) X11_CreateNullCursor (void)
{ {
Pixmap cursormask; Pixmap cursormask;
XGCValues xgc; XGCValues xgc = { };
GC gc; GC gc;
XColor dummycolour; XColor dummycolour = { };
if (nullcursor != None) if (nullcursor != None)
return; return;

View file

@ -842,6 +842,11 @@ Key_IMT_Drop_All_f (void)
while (key_targets[kd].imts) { while (key_targets[kd].imts) {
imt = key_targets[kd].imts; imt = key_targets[kd].imts;
key_targets[kd].imts = imt->next; key_targets[kd].imts = imt->next;
for (int i = 0; i < QFK_LAST; i++) {
if (imt->bindings[i].str) {
free (imt->bindings[i].str);
}
}
free ((char *) imt->name); free ((char *) imt->name);
free (imt); free (imt);
} }