From 4a80a125c03b2a2d3b407ca010217add037da480 Mon Sep 17 00:00:00 2001 From: Don HO Date: Thu, 25 Jul 2019 13:11:42 +0200 Subject: [PATCH] Fix the crash due to NPPM_DESTROYSCINTILLAHANDLE message Destroying allocated Scintilla makes Notepad++ crash because created Scintilla view's pointer is added into _referees of Buffer object automatically. The deallocated scintilla view in _referees is used in Buffer::nextUntitledNewNumber(). So we do nothing here and let Notepad++ destroys allocated Scintilla while it exit and we keep this message for the sake of compability withe the existing plugins. Fix #4487, close #1500, close #5949 --- PowerEditor/src/NppBigSwitch.cpp | 10 +++++++++- PowerEditor/src/ScitillaComponent/ScintillaCtrls.cpp | 2 ++ PowerEditor/src/ScitillaComponent/ScintillaCtrls.h | 2 +- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 013cb3586..726a1323c 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -1244,7 +1244,15 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_DESTROYSCINTILLAHANDLE: { - return _scintillaCtrls4Plugins.destroyScintilla(reinterpret_cast(lParam)); + //return _scintillaCtrls4Plugins.destroyScintilla(reinterpret_cast(lParam)); + + // Destroying allocated Scintilla makes Notepad++ crash + // because created Scintilla view's pointer is added into _referees of Buffer object automatically. + // The deallocated scintilla view in _referees is used in Buffer::nextUntitledNewNumber(). + + // So we do nothing here and let Notepad++ destroy allocated Scintilla while it exits + // and we keep this message for the sake of compability withe the existing plugins. + return true; } case NPPM_GETNBUSERLANG: diff --git a/PowerEditor/src/ScitillaComponent/ScintillaCtrls.cpp b/PowerEditor/src/ScitillaComponent/ScintillaCtrls.cpp index 81a791abc..0f3a101b0 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaCtrls.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaCtrls.cpp @@ -58,6 +58,7 @@ ScintillaEditView * ScintillaCtrls::getScintillaEditViewFrom(HWND handle2Find) return _scintVector[i]; } +/* bool ScintillaCtrls::destroyScintilla(HWND handle2Destroy) { int i = getIndexFrom(handle2Destroy); @@ -71,6 +72,7 @@ bool ScintillaCtrls::destroyScintilla(HWND handle2Destroy) _scintVector.erase(it2delete); return true; } +*/ void ScintillaCtrls::destroy() { diff --git a/PowerEditor/src/ScitillaComponent/ScintillaCtrls.h b/PowerEditor/src/ScitillaComponent/ScintillaCtrls.h index 0cc6351bc..b4e832b51 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaCtrls.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaCtrls.h @@ -43,7 +43,7 @@ public : HWND createSintilla(HWND hParent); ScintillaEditView * getScintillaEditViewFrom(HWND handle2Find); - bool destroyScintilla(HWND handle2Destroy); + //bool destroyScintilla(HWND handle2Destroy); void destroy(); private: