Browse Source

In the original code, there are chances to compare an iterator from m_CBsByName to m_StructuredBufferCBsByName.end(). It crashes if _ITERATOR_DEBUG_LEVEL is not 0. Fix it by comparing an iterator to the container it's from. (#3160)

Co-authored-by: Minmin Gong <[email protected]>
Minmin Gong 4 years ago
parent
commit
65155d95bd
1 changed files with 11 additions and 3 deletions
  1. 11 3
      lib/HLSL/DxilContainerReflection.cpp

+ 11 - 3
lib/HLSL/DxilContainerReflection.cpp

@@ -2323,11 +2323,19 @@ ID3D12ShaderReflectionConstantBuffer* DxilModuleReflection::_GetConstantBufferBy
     return &g_InvalidSRConstantBuffer;
     return &g_InvalidSRConstantBuffer;
   }
   }
 
 
+  size_t index = m_CBs.size();
   auto it = m_CBsByName.find(Name);
   auto it = m_CBsByName.find(Name);
-  if (it == m_CBsByName.end())
+  if (it != m_CBsByName.end()) {
+    index = it->second;
+  } else {
     it = m_StructuredBufferCBsByName.find(Name);
     it = m_StructuredBufferCBsByName.find(Name);
-  if (it != m_StructuredBufferCBsByName.end())
-    return m_CBs[it->second].get();
+    if (it != m_StructuredBufferCBsByName.end()) {
+      index = it->second;
+    }
+  }
+  if (index < m_CBs.size()) {
+    return m_CBs[index].get();
+  }
 
 
   return &g_InvalidSRConstantBuffer;
   return &g_InvalidSRConstantBuffer;
 }
 }