From b98319cb91d9c595c7d43fb1198e0064ffee99c2 Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Thu, 29 Dec 2016 23:42:35 +0100 Subject: [PATCH] CComponentsHeader/CComponentsFooter: prevent crash on changed font settings Default fonts for header and footer must be handled too. After font settings changes these objects could be invalid. Default fonts have invalid pointers after font changes too. Extra reset is required. --- src/gui/components/cc_frm_footer.cpp | 13 ++++++++++++- src/gui/components/cc_frm_footer.h | 3 +++ src/gui/components/cc_frm_header.cpp | 12 +++++++++--- src/gui/components/cc_frm_header.h | 2 ++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/gui/components/cc_frm_footer.cpp b/src/gui/components/cc_frm_footer.cpp index 9874a122b..befc333e8 100644 --- a/src/gui/components/cc_frm_footer.cpp +++ b/src/gui/components/cc_frm_footer.cpp @@ -68,6 +68,12 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const //init footer width width = w == 0 ? frameBuffer->getScreenWidth(true) : w; + //init default fonts + initDefaultFonts(); + + //init default button text font + ccf_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_BUTTON_TEXT]; + //init footer height initCaptionFont(); height = max(h, cch_font->getHeight()); @@ -88,7 +94,6 @@ void CComponentsFooter::initVarFooter( const int& x_pos, const int& y_pos, const corner_type = CORNER_BOTTOM; ccf_enable_button_bg = false /*g_settings.theme.Button_gradient*/; //TODO: not implemented at the moment - ccf_btn_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]; chain = NULL; addContextButton(buttons); @@ -426,3 +431,9 @@ void CComponentsFooter::enableButtonShadow(int mode, const int& shadow_width, bo } } } + +void CComponentsFooter::initDefaultFonts() +{ + l_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]; + s_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_FOOT]; +} diff --git a/src/gui/components/cc_frm_footer.h b/src/gui/components/cc_frm_footer.h index 4c5239d56..b70292765 100644 --- a/src/gui/components/cc_frm_footer.h +++ b/src/gui/components/cc_frm_footer.h @@ -84,6 +84,9 @@ class CComponentsFooter : public CComponentsHeader ///property: set font for label caption, see also setButtonFont() Font* ccf_btn_font; + ///init default fonts for size modes + virtual void initDefaultFonts(); + ///container for button objects CComponentsFrmChain *chain; diff --git a/src/gui/components/cc_frm_header.cpp b/src/gui/components/cc_frm_header.cpp index f746404d4..7f36522c4 100644 --- a/src/gui/components/cc_frm_header.cpp +++ b/src/gui/components/cc_frm_header.cpp @@ -96,8 +96,7 @@ void CComponentsHeader::initVarHeader( const int& x_pos, const int& y_pos, const height = height_old = h; cch_font = NULL; - l_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]; - s_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]; + initDefaultFonts(); cch_size_mode = CC_HEADER_SIZE_LARGE; CNeutrinoApp::getInstance()->OnAfterSetupFonts.connect(sigc::mem_fun(this, &CComponentsHeader::resetFont)); @@ -167,9 +166,16 @@ void CComponentsHeader::setCaptionFont(Font* font) void CComponentsHeader::resetFont() { if (cch_font){ - cch_font = NULL; dprintf(DEBUG_DEBUG, "\033[33m[CComponentsHeader][%s - %d] reset header font \033[0m\n", __func__, __LINE__); + cch_font = NULL; } + initDefaultFonts(); +} + +void CComponentsHeader::initDefaultFonts() +{ + l_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]; + s_font = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]; } void CComponentsHeader::initCaptionFont() diff --git a/src/gui/components/cc_frm_header.h b/src/gui/components/cc_frm_header.h index 98ec74125..df444ee7a 100644 --- a/src/gui/components/cc_frm_header.h +++ b/src/gui/components/cc_frm_header.h @@ -102,6 +102,8 @@ class CComponentsHeader : public CComponentsForm, public CCTextScreen ///init font object and recalculates height if required void initCaptionFont(); + ///init default fonts for size modes + virtual void initDefaultFonts(); ///sub: init icon object void initIcon(); ///sub: init caption object