fubark / cosmic

A platform for computing and creating applications.
https://cosmic.ooo
MIT License
342 stars 16 forks source link

Text_demo 'Load Font' crash #28

Closed wilsonk closed 2 years ago

wilsonk commented 2 years ago

If you try to load the font 'NotoColorEmoji.ttf' from the examples/assets directory (whether copied to the base directory or symlinked) then the example crashes with:

debug(window_gl): 0.0: OpenGL: 4.6 (Core Profile) Mesa 22.0.4
debug(graphics_gl): 0.0: max frag textures: 32, max total textures: 192
debug(window_gl): 0.8: max samples: 8
debug(window_gl): 0.9: msaa framebuffer created with 8 samples
thread 378432 panic: expected color bitmap for glyph: 0
/home/wilsonk/Downloads/zig/build/lib/zig/std/debug.zig:290:22: 0x329ed0 in std.debug.panicExtra (text_demo)
    std.builtin.panic(msg, trace);
                     ^
/home/wilsonk/Downloads/zig/build/lib/zig/std/debug.zig:266:15: 0x3201fa in std.debug.panic (text_demo)
    panicExtra(null, format, args);
              ^
/home/wilsonk/Downloads/cosmic/stdx/debug.zig:25:20: 0x312493 in .ui.graphics.stdx.debug.panicFmt (text_demo)
    std.debug.panic(format, args);
                   ^
/home/wilsonk/Downloads/cosmic/graphics/src/backend/gl/font_renderer.zig:252:22: 0x302f5e in .ui.graphics.backend.gl.font_renderer.generateColorBitmapGlyph (text_demo)
        stdx.panicFmt("expected color bitmap for glyph: {}", .{glyph_id});
                     ^
/home/wilsonk/Downloads/cosmic/graphics/src/backend/gl/font_renderer.zig:58:40: 0x2f3068 in .ui.graphics.backend.gl.font_renderer.generateGlyph (text_demo)
        return generateColorBitmapGlyph(g, ot_font, render_font, glyph_id);
                                       ^
/home/wilsonk/Downloads/cosmic/graphics/src/backend/gl/font_renderer.zig:21:36: 0x2e8cb2 in .ui.graphics.backend.gl.font_renderer.getOrLoadMissingGlyph (text_demo)
        const glyph = generateGlyph(g, font, ot_font, render_font, 0);

Which I suppose means that the NotoColorEmoji.ttf font doesn't have a color bitmap? Anyways, I was wondering if this should/could fail gracefully and produce a warning about the font instead of a crash? I tried a few other fonts and they work fine.

fubark commented 2 years ago

This should be fixed now. Previously it would just look at the color tables and give up if it got back nothing. Now it will also check the outline tables too. If there's a missing glyph it would just be an empty glyph. If you want fallback fonts instead, that can be achieved with graphics.Graphics.addFallbackFont