QPixmapCache: assert that the key is invalid if we failed to insert

QCache::insert on failure destroys the QPixmapCacheEntry, which calls
releaseKey(), which invalidates the key. That's hard to follow, so add
an assert to make it more explicit and prevent future errors.

Change-Id: I9c062ef5a6e34c783c064330c914ce4f9a3f9984
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
(cherry picked from commit ee956824db495c12f51dd0d864e009f0417464d5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Volker Hilsheimer 2023-07-07 10:38:38 +02:00 committed by Qt Cherry-pick Bot
parent 2d4827ac53
commit e7ce9a6546

View File

@ -317,6 +317,7 @@ QPixmapCache::Key QPMCache::insert(const QPixmap &pixmap, int cost)
{
QPixmapCache::Key cacheKey = createKey(); // invalidated by ~QPixmapCacheEntry on failed insert
bool success = QCache<QPixmapCache::Key, QPixmapCacheEntry>::insert(cacheKey, new QPixmapCacheEntry(cacheKey, pixmap), cost);
Q_ASSERT(success || !cacheKey.isValid());
if (success) {
if (!theid) {
theid = startTimer(flush_time);