Added address sanitizer, and stored font/texture names

main
noah metz 2024-10-21 12:30:19 -06:00
parent 5e74250fd3
commit d4790a8d53
3 changed files with 19 additions and 14 deletions

@ -1,5 +1,5 @@
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
CFLAGS = -I $(ROOT_DIR)/include -I/usr/local/include -O0 -g -Wall -Wextra CFLAGS = -I $(ROOT_DIR)/include -I/usr/local/include -O0 -g -Wall -Wextra -fsanitize=address
LDFLAGS = -lfreetype -lz -lglfw -lvulkan -ldl -Xlinker -rpath -Xlinker /opt/homebrew/lib LDFLAGS = -lfreetype -lz -lglfw -lvulkan -ldl -Xlinker -rpath -Xlinker /opt/homebrew/lib
SOURCES = src/main.c src/render.c src/ui.c src/command.c lib/spng.c lib/vma.cpp SOURCES = src/main.c src/render.c src/ui.c src/command.c lib/spng.c lib/vma.cpp

@ -162,8 +162,8 @@ typedef struct UIContextStorageStruct {
uint32_t max_fonts; uint32_t max_fonts;
uint32_t max_textures; uint32_t max_textures;
uint8_t* font_slots; char** font_slots;
uint8_t* texture_slots; char** texture_slots;
UIContext data; UIContext data;
} UIContextStorage; } UIContextStorage;

@ -378,8 +378,9 @@ VkResult load_texture(
TextureStorage* memory) { TextureStorage* memory) {
*index = 0xFFFFFFFF; *index = 0xFFFFFFFF;
for(uint32_t i = 0; i < context->max_textures; i++) { for(uint32_t i = 0; i < context->max_textures; i++) {
if(context->texture_slots[i] == 0) { if(context->texture_slots[i] == NULL) {
context->texture_slots[i] = 1; context->texture_slots[i] = malloc(strlen(png_path) + 1);
memcpy(context->texture_slots[i], png_path, strlen(png_path) + 1);
*index = i; *index = i;
break; break;
} }
@ -593,10 +594,22 @@ VkResult load_font(
VkBool32 antialias, VkBool32 antialias,
uint32_t* index, uint32_t* index,
FontStorage* memory) { FontStorage* memory) {
FT_Face face;
int error;
error = FT_New_Face(library, ttf_file, 0, &face);
if(error != FT_Err_Ok) {
return VK_ERROR_UNKNOWN;
}
*index = 0xFFFFFFFF; *index = 0xFFFFFFFF;
for(uint32_t i = 0; i < context->max_fonts; i++) { for(uint32_t i = 0; i < context->max_fonts; i++) {
if(context->font_slots[i] == 0) { if(context->font_slots[i] == 0) {
context->font_slots[i] = 1; context->font_slots[i] = malloc(strlen(face->family_name) + strlen(face->style_name) + 2);
memcpy(context->font_slots[i], face->family_name, strlen(face->family_name));
context->font_slots[i][strlen(face->family_name)] = ':';
memcpy(context->font_slots[i] + strlen(face->family_name) + 1, face->style_name, strlen(face->style_name));
context->font_slots[i][strlen(face->family_name) + strlen(face->style_name) + 1] = '\0';
*index = i; *index = i;
break; break;
} }
@ -605,14 +618,6 @@ VkResult load_font(
return VK_ERROR_OUT_OF_DEVICE_MEMORY; return VK_ERROR_OUT_OF_DEVICE_MEMORY;
} }
FT_Face face;
int error;
error = FT_New_Face(library, ttf_file, 0, &face);
if(error != FT_Err_Ok) {
return VK_ERROR_UNKNOWN;
}
error = FT_Set_Pixel_Sizes(face, 0, size); error = FT_Set_Pixel_Sizes(face, 0, size);
if(error != FT_Err_Ok) { if(error != FT_Err_Ok) {
return VK_ERROR_UNKNOWN; return VK_ERROR_UNKNOWN;