From 9f07b073dc8f751a7882185fcc076ac77da2fab7 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 20 Apr 2018 12:01:04 +0100 Subject: [PATCH] Fix vector iterator invalidation properly - store as index and restore * The previous fix was insufficient, the iterator being at end() is only one way push_back can invalidate it, the other is if the array being expanded is large enough (or things are just right) that the vector resizes. --- renderdoc/driver/shaders/dxbc/dxbc_inspect.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/renderdoc/driver/shaders/dxbc/dxbc_inspect.cpp b/renderdoc/driver/shaders/dxbc/dxbc_inspect.cpp index 2a4caec7f..1f5c0765c 100644 --- a/renderdoc/driver/shaders/dxbc/dxbc_inspect.cpp +++ b/renderdoc/driver/shaders/dxbc/dxbc_inspect.cpp @@ -700,9 +700,9 @@ DXBCFile::DXBCFile(const void *ByteCode, size_t ByteCodeLength) // remove the array item, and get the iterator to the next item to process it = resArray.erase(it); - // if we're now pointing at the end of the vector, save that, as the iterator will be - // invalid after we push back below. - bool last = (it == resArray.end()); + // store the iterator index, as it may be invalidated by vector resizing below, or if + // it's pointing at end(). + size_t itIdx = it - resArray.begin(); string rname = desc.name; uint32_t arraySize = desc.bindCount; @@ -716,9 +716,7 @@ DXBCFile::DXBCFile(const void *ByteCode, size_t ByteCodeLength) desc.reg++; } - // if we just expanded the last item, break out of the loop - if(last) - break; + it = resArray.begin() + itIdx; continue; }