diff options
author | Robert Griebl <robert.griebl@qt.io> | 2023-05-15 11:47:59 +0200 |
---|---|---|
committer | Robert Griebl <robert.griebl@qt.io> | 2023-05-15 12:22:06 +0200 |
commit | 4e1cc1b01aec7528e9789dffb84a260d129e9d14 (patch) | |
tree | 8639585397b86a98c7e2c6db6d6a56dab210f3dd | |
parent | df02b3f36cfda76d5b027cd34f42266f16b596c2 (diff) |
Fix UB on iterate and erase
The old code at least doesn't crash on Qt 5, but it's UB.
The same code will crash on Qt 6 though.
Change-Id: I53f7c683b4d3044921a0a34723b503885f454699
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
-rw-r--r-- | src/runtimerender/Qt3DSDistanceFieldRenderer.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp b/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp index f673f2e..6378660 100644 --- a/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp +++ b/src/runtimerender/Qt3DSDistanceFieldRenderer.cpp @@ -97,27 +97,27 @@ void Q3DSDistanceFieldRenderer::EndFrame() // Remove meshes for glyphs that weren't rendered last frame NVAllocatorCallback &alloc = m_context->GetAllocator(); - QHash<size_t, QHash<Q3DSDistanceFieldGlyphCache::TextureInfo *, GlyphInfo>>::const_iterator - glyphIt = m_glyphCache.constBegin(); - while (glyphIt != m_glyphCache.constEnd()) { + QHash<size_t, QHash<Q3DSDistanceFieldGlyphCache::TextureInfo *, GlyphInfo>>::iterator + glyphIt = m_glyphCache.begin(); + while (glyphIt != m_glyphCache.end()) { const size_t textHash = glyphIt.key(); if (!m_renderedTexts.contains(textHash)) - m_glyphCache.erase(glyphIt++); + glyphIt = m_glyphCache.erase(glyphIt); else - glyphIt++; + ++glyphIt; } - QHash<size_t, Q3DSDistanceFieldMesh>::const_iterator meshIt = m_meshCache.constBegin(); - while (meshIt != m_meshCache.constEnd()) { + QHash<size_t, Q3DSDistanceFieldMesh>::iterator meshIt = m_meshCache.begin(); + while (meshIt != m_meshCache.end()) { const size_t glyphHash = meshIt.key(); const Q3DSDistanceFieldMesh &mesh = meshIt.value(); if (!m_renderedGlyphs.contains(glyphHash)) { NVDelete(alloc, mesh.vertexBuffer); NVDelete(alloc, mesh.indexBuffer); NVDelete(alloc, mesh.inputAssembler); - m_meshCache.erase(meshIt++); + meshIt = m_meshCache.erase(meshIt); } else { - meshIt++; + ++meshIt; } } |