From e6a0d2fce6c6557fbe27f1f373aab518995394f5 Mon Sep 17 00:00:00 2001 From: Roman Kuznetsov Date: Wed, 27 Sep 2023 10:07:38 -0700 Subject: [PATCH] Add reporting if uniform block in not found by binding index Summary: `at(0)` can raise exception if exceptions are enabled, otherwise result is undefined. Reviewed By: francoiscoulombe Differential Revision: D49685003 fbshipit-source-id: 6f72ecde3b1825492ded3ff0c69eb1a8ff5eda71 --- src/igl/opengl/RenderPipelineState.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/igl/opengl/RenderPipelineState.cpp b/src/igl/opengl/RenderPipelineState.cpp index eaa36b2eb9..9780ad1716 100644 --- a/src/igl/opengl/RenderPipelineState.cpp +++ b/src/igl/opengl/RenderPipelineState.cpp @@ -157,7 +157,7 @@ Result RenderPipelineState::create(const RenderPipelineDesc& desc) { if (blockIndex >= 0) { uniformBlockBindingMap_[blockIndex] = bindingIndex; } else { - IGL_LOG_ERROR("uniform block (%s) not found in shader.\n", blockName.toConstChar()); + IGL_LOG_ERROR("Uniform block (%s) not found in shader.\n", blockName.toConstChar()); } } @@ -364,7 +364,14 @@ int RenderPipelineState::getIndexByName(const std::string& name, ShaderStage /*s int RenderPipelineState::getUniformBlockBindingPoint(const NameHandle& uniformBlockName) const { const int blockIndex = getIndexByName(uniformBlockName, ShaderStage::Fragment); - return uniformBlockBindingMap_.at(blockIndex); + auto it = uniformBlockBindingMap_.find(blockIndex); + if (it == uniformBlockBindingMap_.end()) { + IGL_LOG_ERROR("Uniform block (%s) with index (%d) not found in the block binding map.\n", + uniformBlockName.toConstChar(), + blockIndex); + return -1; + } + return it->second; } std::shared_ptr RenderPipelineState::renderPipelineReflection() {