Tue, 05 Aug 2025 20:38:11 +0200
fix wrong text length stored in asc_text_printf()
src/text.c | file | annotate | diff | comparison | revisions |
--- a/src/text.c Tue Aug 05 20:06:35 2025 +0200 +++ b/src/text.c Tue Aug 05 20:38:11 2025 +0200 @@ -73,9 +73,8 @@ }; TTF_SetFontWrapAlignment( font, alignments[text->base.flags & ASC_TEXT_ALIGNMENT_MASK]); - // TODO: it looks like TTF_RenderText_Blended_Wrapped is broken in SDL 3 - SDL_Surface *surface = TTF_RenderText_Blended( - font, text->text.ptr, text->text.length, asc_col_sdl(text->color)//, text->max_width + SDL_Surface *surface = TTF_RenderText_Blended_Wrapped( + font, text->text.ptr, text->text.length, asc_col_sdl(text->color), text->max_width ); if (surface == NULL) { asc_error("Rendering TTF surface failed: %s", SDL_GetError()); @@ -210,15 +209,22 @@ const char *format, ... ) { + size_t buflen = node->text.length + 1; va_list ap; va_start(ap, format); - cx_vsprintf( + int ret = cx_vsprintf( &node->text.ptr, - &node->text.length, + &buflen, format, ap ); va_end(ap); + if (ret < 0) { + asc_wprintf("Unexpected error code when formatting text: %d", ret); + node->text.length = 0; + } else { + node->text.length = ret; + } asc_scene_node_update((AscSceneNode*)node); }