From 51a5fbfd59973681d96392e3541635b1250ad28d Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 27 Dec 2014 00:32:51 +0000 Subject: [PATCH] [BUG_FIXED] Fix the crash issue while config.xml and stylers.xml are not loaded. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1319 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 9 ++++++--- PowerEditor/src/Notepad_plus_Window.cpp | 3 +-- PowerEditor/src/Parameters.h | 12 ++++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index fafb5ab1..5aa29f9b 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -665,9 +665,12 @@ LRESULT Notepad_plus::init(HWND hwnd) // StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers(); int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT); - Style & style = globalStyles.getStyler(i); - (NppParameters::getInstance())->setCurrentDefaultFgColor(style._fgColor); - (NppParameters::getInstance())->setCurrentDefaultBgColor(style._bgColor); + if (i != -1) + { + Style & style = globalStyles.getStyler(i); + (NppParameters::getInstance())->setCurrentDefaultFgColor(style._fgColor); + (NppParameters::getInstance())->setCurrentDefaultBgColor(style._bgColor); + } // // launch the plugin dlg memorized at the last session diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp index a9f4a306..3c258ea7 100644 --- a/PowerEditor/src/Notepad_plus_Window.cpp +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -161,7 +161,7 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin patterns.push_back(TEXT("*.xml")); generic_string nppDir = pNppParams->getNppPath(); -#ifdef UNICODE + LocalizationSwitcher & localizationSwitcher = pNppParams->getLocalizationSwitcher(); wstring localizationDir = nppDir; PathAppend(localizationDir, TEXT("localization\\")); @@ -171,7 +171,6 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin { localizationSwitcher.addLanguageFromXml(fileNames[i].c_str()); } -#endif fileNames.clear(); ThemeSwitcher & themeSwitcher = pNppParams->getThemeSwitcher(); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index bd583ba5..56df9ade 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -397,7 +397,14 @@ public: void setNbStyler(int nb) {_nbStyler = nb;}; Style & getStyler(int index) { - assert(index != -1); + assert(index >= 0 && index < SCE_STYLE_ARRAY_SIZE); + /* + if (index < 0 || index >= SCE_STYLE_ARRAY_SIZE) + { + Style s; + return s; + } + */ return _styleArray[index]; }; @@ -1534,7 +1541,8 @@ public: }; void saveConfig_xml() { - _pXmlUserDoc->SaveFile(); + if (_pXmlUserDoc) + _pXmlUserDoc->SaveFile(); }; generic_string getUserPath() const {