From 01de38b20d94436492e351a75e2f29e9bab3aac9 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 31 May 2023 22:03:27 -0700 Subject: [PATCH] font: if CoreText needs to allocate, stack allocate and log --- src/font/DeferredFace.zig | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/font/DeferredFace.zig b/src/font/DeferredFace.zig index 94fd7bd10..a91589b59 100644 --- a/src/font/DeferredFace.zig +++ b/src/font/DeferredFace.zig @@ -113,7 +113,21 @@ pub fn name(self: DeferredFace) ![:0]const u8 { .coretext, .coretext_freetype => if (self.ct) |ct| { const display_name = ct.font.copyDisplayName(); - return display_name.cstringPtr(.utf8) orelse ""; + return display_name.cstringPtr(.utf8) orelse unsupported: { + // "NULL if the internal storage of theString does not allow + // this to be returned efficiently." In this case, we need + // to allocate. But we can't return an allocated string because + // we don't have an allocator. Let's use the stack and log it. + var buf: [1024]u8 = undefined; + const buf_name = display_name.cstring(&buf, .utf8) orelse + ""; + + log.info( + "CoreText font required too much space to copy, value = {s}", + .{buf_name}, + ); + break :unsupported ""; + }; }, .web_canvas => if (self.wc) |wc| return wc.font_str,