|
|
|
|
@ -234,40 +234,74 @@ VkResult create_ui_pipeline(
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Layer structs come from uninitialized malloc, so cleanup is gated on the
|
|
|
|
|
// data.* count fields create_layer always sets, not on pointer NULL checks
|
|
|
|
|
static void destroy_layer(Layer* layer, RenderContext* gpu) {
|
|
|
|
|
for(uint32_t f = 0; f < MAX_FRAMES_IN_FLIGHT; f++) {
|
|
|
|
|
retire_buffer(layer->layer[f], layer->layer_memory[f], gpu);
|
|
|
|
|
if(layer->data.max_strings > 0) {
|
|
|
|
|
retire_buffer(layer->strings[f], layer->strings_memory[f], gpu);
|
|
|
|
|
}
|
|
|
|
|
if(layer->data.max_drawables > 0) {
|
|
|
|
|
retire_buffer(layer->drawables[f], layer->drawables_memory[f], gpu);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(layer->data.max_strings > 0) {
|
|
|
|
|
for(uint32_t s = 0; s < layer->data.max_strings; s++) {
|
|
|
|
|
if(layer->string_resources[s].codes_buffer == NULL) continue;
|
|
|
|
|
for(uint32_t f = 0; f < MAX_FRAMES_IN_FLIGHT; f++) {
|
|
|
|
|
retire_buffer(layer->string_resources[s].codes[f], layer->string_resources[s].codes_memory[f], gpu);
|
|
|
|
|
}
|
|
|
|
|
free(layer->string_resources[s].codes_buffer);
|
|
|
|
|
}
|
|
|
|
|
free(layer->string_resources);
|
|
|
|
|
free(layer->strings_buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(layer->data.num_drawables > 0) {
|
|
|
|
|
free(layer->drawables_buffer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult unload_container(
|
|
|
|
|
uint32_t id,
|
|
|
|
|
RenderContext* gpu,
|
|
|
|
|
UIContext* context) {
|
|
|
|
|
uint32_t index = 0xFFFFFFFF;
|
|
|
|
|
for(uint32_t i = 0; i < context->max_containers; i++) {
|
|
|
|
|
if(context->containers[i].id == id) {
|
|
|
|
|
index = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(index == 0xFFFFFFFF) {
|
|
|
|
|
Container* container = context_container(id, context);
|
|
|
|
|
if(container == NULL) {
|
|
|
|
|
return VK_ERROR_VALIDATION_FAILED_EXT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context->containers[index].id = 0;
|
|
|
|
|
for(uint32_t l = 0; l < container->layer_count; l++) {
|
|
|
|
|
destroy_layer(&container->layers[l], gpu);
|
|
|
|
|
}
|
|
|
|
|
free(container->layers);
|
|
|
|
|
container->layers = NULL;
|
|
|
|
|
container->layer_count = 0;
|
|
|
|
|
|
|
|
|
|
for(uint32_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
|
|
|
|
vmaDestroyBuffer(gpu->allocator, context->containers[index].container[i], context->containers[index].container_memory[i]);
|
|
|
|
|
context->containers[index].address[i] = 0;
|
|
|
|
|
retire_buffer(container->container[i], container->container_memory[i], gpu);
|
|
|
|
|
container->address[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
context->containers[index].layer_count = 0;
|
|
|
|
|
// Drop focus without dispatching on_deselect: the script is being unloaded
|
|
|
|
|
if(context->active_container == container) {
|
|
|
|
|
context->active_container = NULL;
|
|
|
|
|
context->active_element = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(context->containers[index].script_env != 0) {
|
|
|
|
|
luaL_unref(context->lua, LUA_REGISTRYINDEX, context->containers[index].script_env);
|
|
|
|
|
context->containers[index].script_env = 0;
|
|
|
|
|
if(container->script_env != 0) {
|
|
|
|
|
luaL_unref(context->lua, LUA_REGISTRYINDEX, container->script_env);
|
|
|
|
|
container->script_env = 0;
|
|
|
|
|
}
|
|
|
|
|
if(context->containers[index].script_path != NULL) {
|
|
|
|
|
free(context->containers[index].script_path);
|
|
|
|
|
context->containers[index].script_path = NULL;
|
|
|
|
|
if(container->script_path != NULL) {
|
|
|
|
|
free(container->script_path);
|
|
|
|
|
container->script_path = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
container->id = 0;
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|