From a6436ff5592332d5d06c6ee1806dc132306d5f3e Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 8 Dec 2014 13:58:13 +0100 Subject: [PATCH] Windows: Limit cursor cache. Prevent the cursor cache from growing indefinitely hitting GDI resource limits if new pixmap cursors are created repetitively by purging out all-noncurrent pixmap cursors. Change-Id: I4a3bbd6235af13e306ca84ac6fea3fcd69d53279 Reviewed-by: Joerg Bornemann --- src/plugins/platforms/windows/qwindowscursor.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/platforms/windows/qwindowscursor.cpp b/src/plugins/platforms/windows/qwindowscursor.cpp index f5d6c140bf..d10c7fdb20 100644 --- a/src/plugins/platforms/windows/qwindowscursor.cpp +++ b/src/plugins/platforms/windows/qwindowscursor.cpp @@ -570,8 +570,21 @@ QWindowsWindowCursor QWindowsCursor::pixmapWindowCursor(const QCursor &c) { const QWindowsCursorCacheKey cacheKey(c); CursorCache::iterator it = m_cursorCache.find(cacheKey); - if (it == m_cursorCache.end()) + if (it == m_cursorCache.end()) { + if (m_cursorCache.size() > 50) { + // Prevent the cursor cache from growing indefinitely hitting GDI resource + // limits if new pixmap cursors are created repetitively by purging out + // all-noncurrent pixmap cursors (QTBUG-43515) + const HCURSOR currentCursor = GetCursor(); + for (it = m_cursorCache.begin(); it != m_cursorCache.end() ; ) { + if (it.key().bitmapCacheKey && it.value().handle() != currentCursor) + it = m_cursorCache.erase(it); + else + ++it; + } + } it = m_cursorCache.insert(cacheKey, QWindowsWindowCursor(c)); + } return it.value(); }