use SDL stdlib where possible

This commit is contained in:
2024-09-25 19:42:34 -03:00
parent ccad21ab90
commit 0fe1023667
9 changed files with 37 additions and 39 deletions

View File

@ -53,16 +53,16 @@ static FontData *text_load_font_data(const char *path, int height_px) {
TEXT_FONT_TEXTURE_SIZE,
TEXT_FONT_TEXTURE_SIZE
);
free(bitmap);
SDL_free(bitmap);
return font_data;
}
static void text_destroy_font_data(FontData *font_data) {
free(font_data->file_bytes);
SDL_free(font_data->file_bytes);
delete_gpu_texture(font_data->texture);
free(font_data);
SDL_free(font_data);
}
@ -114,7 +114,7 @@ static void ensure_font_cache(const char *font_path, int height_px) {
bool is_cached = false;
for (size_t i = 0; i < arrlenu(ctx.text_cache.data); ++i) {
FontData *font_data = ctx.text_cache.data[i];
if ((strcmp(font_path, font_data->file_path) == 0) && height_px == font_data->height_px) {
if ((SDL_strcmp(font_path, font_data->file_path) == 0) && height_px == font_data->height_px) {
is_cached = true;
break;
}
@ -130,7 +130,7 @@ static FontData *get_font_data(const char *font_path, int height_px) {
FontData *font_data = NULL;
for (size_t i = 0; i < arrlenu(ctx.text_cache.data); ++i) {
font_data = ctx.text_cache.data[i];
if ((strcmp(font_path, font_data->file_path) == 0) && height_px == font_data->height_px) {
if ((SDL_strcmp(font_path, font_data->file_path) == 0) && height_px == font_data->height_px) {
break;
}
}
@ -161,11 +161,9 @@ void text_cache_deinit(TextCache *cache) {
void push_text(char *string, Vec2 position, int height_px, Color color, const char *font_path) {
ensure_font_cache(font_path, height_px);
/* the string might not be around by the time it's used, so copy it */
/* the original string might not be around by the time it's used, so copy it */
/* TODO: arena */
/* NOTE: can we trust strlen? */
char *dup_string = cmalloc(strlen(string) + 1);
strcpy(dup_string, string);
char *dup_string = SDL_strdup(string);
TextPrimitive text = {
.color = color,