aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2020-03-17 09:07:15 +1100
committerNeil <nyamatongwe@gmail.com>2020-03-17 09:07:15 +1100
commitd37556bb750b9e03263036ea2e6afe4ee8dab79a (patch)
tree9ebb20a664fb8076b39ff08c69d4a92b8b341dd0
parent491936de90da48034097820f877aa3655f3cd09a (diff)
downloadscintilla-mirror-d37556bb750b9e03263036ea2e6afe4ee8dab79a.tar.gz
Backport: Remove CRITICAL_SECTION by creating reverse arrow cursor at initialization.
InitializeCriticalSection inside DllMain can cause exceptions on old Windows. Backport of changeset 8009:ef650c1aa3ca.
-rw-r--r--win32/PlatWin.cxx47
1 files changed, 17 insertions, 30 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx
index 27d40fe22..bca0bd5f0 100644
--- a/win32/PlatWin.cxx
+++ b/win32/PlatWin.cxx
@@ -254,7 +254,6 @@ void SetWindowPointer(HWND hWnd, void *ptr) noexcept {
::SetWindowLongPtr(hWnd, 0, reinterpret_cast<LONG_PTR>(ptr));
}
-CRITICAL_SECTION crPlatformLock;
HINSTANCE hinstPlatformRes {};
HCURSOR reverseArrowCursor {};
@@ -1823,35 +1822,24 @@ void FlipBitmap(HBITMAP bitmap, int width, int height) noexcept {
}
}
-HCURSOR GetReverseArrowCursor() noexcept {
- if (reverseArrowCursor)
- return reverseArrowCursor;
-
- ::EnterCriticalSection(&crPlatformLock);
- HCURSOR cursor = reverseArrowCursor;
- if (!cursor) {
- cursor = ::LoadCursor(NULL, IDC_ARROW);
- ICONINFO info;
- if (::GetIconInfo(cursor, &info)) {
- BITMAP bmp;
- if (::GetObject(info.hbmMask, sizeof(bmp), &bmp)) {
- FlipBitmap(info.hbmMask, bmp.bmWidth, bmp.bmHeight);
- if (info.hbmColor)
- FlipBitmap(info.hbmColor, bmp.bmWidth, bmp.bmHeight);
- info.xHotspot = bmp.bmWidth - 1 - info.xHotspot;
-
- reverseArrowCursor = ::CreateIconIndirect(&info);
- if (reverseArrowCursor)
- cursor = reverseArrowCursor;
- }
-
- ::DeleteObject(info.hbmMask);
+void LoadReverseArrowCursor() noexcept {
+ HCURSOR cursor = ::LoadCursor({}, IDC_ARROW);
+ ICONINFO info;
+ if (::GetIconInfo(cursor, &info)) {
+ BITMAP bmp;
+ if (::GetObject(info.hbmMask, sizeof(bmp), &bmp)) {
+ FlipBitmap(info.hbmMask, bmp.bmWidth, bmp.bmHeight);
if (info.hbmColor)
- ::DeleteObject(info.hbmColor);
+ FlipBitmap(info.hbmColor, bmp.bmWidth, bmp.bmHeight);
+ info.xHotspot = bmp.bmWidth - 1 - info.xHotspot;
+
+ reverseArrowCursor = ::CreateIconIndirect(&info);
}
+
+ ::DeleteObject(info.hbmMask);
+ if (info.hbmColor)
+ ::DeleteObject(info.hbmColor);
}
- ::LeaveCriticalSection(&crPlatformLock);
- return cursor;
}
}
@@ -1877,7 +1865,7 @@ void Window::SetCursor(Cursor curs) {
::SetCursor(::LoadCursor(NULL,IDC_HAND));
break;
case cursorReverseArrow:
- ::SetCursor(GetReverseArrowCursor());
+ ::SetCursor(reverseArrowCursor);
break;
case cursorArrow:
case cursorInvalid: // Should not occur, but just in case.
@@ -2927,8 +2915,8 @@ void Platform::Assert(const char *c, const char *file, int line) {
}
void Platform_Initialise(void *hInstance) {
- ::InitializeCriticalSection(&crPlatformLock);
hinstPlatformRes = static_cast<HINSTANCE>(hInstance);
+ LoadReverseArrowCursor();
ListBoxX_Register();
}
@@ -2964,7 +2952,6 @@ void Platform_Finalise(bool fromDllMain) {
if (reverseArrowCursor)
::DestroyCursor(reverseArrowCursor);
ListBoxX_Unregister();
- ::DeleteCriticalSection(&crPlatformLock);
}
}