From 08668e8084f0f4e9a639ae641b557c4691392510 Mon Sep 17 00:00:00 2001 From: Caoimhe Date: Fri, 24 Mar 2023 19:45:41 +0000 Subject: LibGUI: Fix crash when not using a custom font in `GlyphMapWidget` `m_original_font` is only set if `GlyphMapWidget::set_font` is called. But, if the user of `GlyphMapWidget` decides not to set a font, there will be no value for `m_original_font`. This commit fixes that issue by checking if `m_original_font` is not null before attempting to use it. --- Userland/Libraries/LibGUI/GlyphMapWidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp index e63e3de1ab..ce7b6accce 100644 --- a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp +++ b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp @@ -49,6 +49,7 @@ void GlyphMapWidget::Selection::extend_to(int glyph) } GlyphMapWidget::GlyphMapWidget() + : AbstractScrollableWidget() { set_focus_policy(FocusPolicy::StrongFocus); horizontal_scrollbar().set_visible(false); @@ -145,7 +146,7 @@ void GlyphMapWidget::paint_event(PaintEvent& event) painter.draw_emoji(inner_rect.location(), *emoji, font()); } else if (font().contains_glyph(glyph)) { if (m_highlight_modifications && m_modified_glyphs.contains(glyph)) { - if (m_original_font->contains_glyph(glyph)) { + if (m_original_font && m_original_font->contains_glyph(glyph)) { // Modified if (palette().is_dark()) painter.fill_rect(outer_rect, Gfx::Color { 0, 65, 159 }); @@ -165,7 +166,7 @@ void GlyphMapWidget::paint_event(PaintEvent& event) } else if (auto* emoji = Gfx::Emoji::emoji_for_code_point(glyph); emoji && m_show_system_emoji) { painter.draw_emoji(inner_rect.location(), *emoji, font()); } else { - if (m_highlight_modifications && m_original_font->contains_glyph(glyph)) { + if (m_highlight_modifications && m_original_font && m_original_font->contains_glyph(glyph)) { // Deleted if (palette().is_dark()) painter.fill_rect(outer_rect, Gfx::Color { 127, 0, 0 }); -- cgit v1.2.3