From 8548d090fcdd983b355a059ae6313d0fef133bb5 Mon Sep 17 00:00:00 2001 From: Samuel Gomes Date: Thu, 14 Sep 2023 07:19:22 +0530 Subject: [PATCH] Fix macOS seg-fault reported by @grymmjack --- .gitignore | 1 + internal/c/parts/video/font/font.cpp | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4d16dc0a4..b6004fbfd 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ internal/c/qbx[2-9].cpp mingw32.exe mingw64.exe .vscode +.DS_Store diff --git a/internal/c/parts/video/font/font.cpp b/internal/c/parts/video/font/font.cpp index 6e52f2ac1..687bd1cf9 100644 --- a/internal/c/parts/video/font/font.cpp +++ b/internal/c/parts/video/font/font.cpp @@ -876,6 +876,8 @@ int32_t FontPrintWidthUTF32(int32_t fh, const uint32_t *codepoint, int32_t codep if (codepoints > 0) { FONT_DEBUG_CHECK(IS_VALID_FONT_HANDLE(fh)); + FONT_DEBUG_PRINT("codepoint = %p, codepoints = %i", codepoint, codepoints); + // Get the actual width in pixels return fontManager.fonts[fh]->GetStringPixelWidth(codepoint, codepoints); } @@ -893,7 +895,8 @@ int32_t FontPrintWidthASCII(int32_t fh, const uint8_t *codepoint, int32_t codepo FONT_DEBUG_CHECK(IS_VALID_FONT_HANDLE(fh)); // Atempt to convert the string to UTF32 and get the actual width in pixels - return FontPrintWidthUTF32(fh, utf32.codepoints.data(), utf32.ConvertASCII(codepoint, codepoints)); + auto count = utf32.ConvertASCII(codepoint, codepoints); + return FontPrintWidthUTF32(fh, utf32.codepoints.data(), count); } return 0; @@ -995,7 +998,8 @@ bool FontRenderTextASCII(int32_t fh, const uint8_t *codepoint, int32_t codepoint FONT_DEBUG_CHECK(IS_VALID_FONT_HANDLE(fh)); // Atempt to convert the string to UTF32 and forward to FontRenderTextUTF32() - return FontRenderTextUTF32(fh, utf32.codepoints.data(), utf32.ConvertASCII(codepoint, codepoints), options, out_data, out_x, out_y); + auto count = utf32.ConvertASCII(codepoint, codepoints); + return FontRenderTextUTF32(fh, utf32.codepoints.data(), count, options, out_data, out_x, out_y); } return false;