Skip to content

Custom font works in debug mode but not in release mode #5837

@0thElement

Description

@0thElement

Describe the bug

Adding custom fonts to egui displays properly in debug mode, but in release mode all glyphs are displayed as squares.
Below are relevant screenshots. It can be observed that japanese characters and icons are not displayed properly.

To Reproduce
Steps to reproduce the behavior:
Here's the code for setting up egui context, although I've tried several other methods, none of them work.
The egui_phosphor crate was used to provide phosphor icon font.

        let egui_context = Context::default();
        let id = egui_context.viewport_id();

        const BORDER_RADIUS: u8 = 5;

        let visuals = Visuals {
            window_corner_radius: egui::CornerRadius::same(BORDER_RADIUS),
            window_shadow: egui::Shadow::NONE,
            menu_corner_radius: egui::CornerRadius::same(BORDER_RADIUS),
            panel_fill: egui::Color32::from_rgba_unmultiplied(0, 0, 0, 0),
            ..Default::default()
        };

        egui_context.set_visuals(visuals);

        let egui_state =
            egui_winit::State::new(egui_context.clone(), id, &window, None, None, None);

        // egui_state.set_pixels_per_point(window.scale_factor() as f32);
        let egui_renderer = egui_wgpu::Renderer::new(
            device,
            output_color_format,
            output_depth_format,
            msaa_samples,
            false,
        );

        egui_context.add_font(egui::epaint::text::FontInsert {
            name: "notosans-jp".into(),
            data: egui::FontData::from_static(include_bytes!("NotoSansJP-Regular.ttf")),
            families: vec![
                egui::epaint::text::InsertFontFamily {
                    family: egui::FontFamily::Proportional,
                    priority: egui::epaint::text::FontPriority::Lowest,
                },
                egui::epaint::text::InsertFontFamily {
                    family: egui::FontFamily::Monospace,
                    priority: egui::epaint::text::FontPriority::Lowest,
                },
            ],
        });

        egui_context.add_font(egui::epaint::text::FontInsert {
            name: "phosphor".into(),
            data: egui_phosphor::Variant::Fill.font_data(),
            families: vec![egui::epaint::text::InsertFontFamily {
                family: egui::FontFamily::Proportional,
                priority: egui::epaint::text::FontPriority::Lowest,
            }],
        });

Expected behavior
Expected behaviour: All glyphs are displayed properly.

Screenshots
Release mode:
Image
Debug mode:
Image

Desktop (please complete the following information):

  • OS: Observed on Windows 11 and MacOS 15.2.0
  • Browser: Not applicable
  • Version: Not applicable

Smartphone (please complete the following information):

  • Device: Not applicable
  • OS: Not applicable
  • Browser: Not applicable
  • Version: Not applicable

Additional context
Observed on egui 0.31 and the latest commit on master.
Currently using egui together with egui_wgpu and egui_winit.
If it helps, here's the relevant profile settings in Cargo.toml. I have tried removing strip = true but the issue still persists

[workspace.dependencies]
winit = {version = "0.30.9", features = [ "android-native-activity", "rwh_06" ]}
wgpu = "24.0.0"
egui = { version = "0.31.1", features = [ "persistence" ]}
egui-wgpu = "0.31.1"
egui-winit = "0.31.1"
egui-phosphor = { version = "0.9.0", features = ["fill"] }
egui_extras = { version = "0.31.1", default-features = false, features = [ "serde" ]}

[profile.dev]
opt-level = 1

[profile.dev.package."*"]
opt-level = 3

[profile.release]
strip = true

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions