From 008c958a7593509515f6ff6585484a0c9a92cf63 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 3 Apr 2023 18:48:03 +0900 Subject: [PATCH] Fix index out of range with SSBOs --- src/libveldrid-spirv/libveldrid-spirv.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/libveldrid-spirv/libveldrid-spirv.cpp b/src/libveldrid-spirv/libveldrid-spirv.cpp index 37b6dec..2a82fda 100644 --- a/src/libveldrid-spirv/libveldrid-spirv.cpp +++ b/src/libveldrid-spirv/libveldrid-spirv.cpp @@ -442,12 +442,18 @@ CompilationResult *CompileVertexFragment(const CrossCompileInfo &info) if (info.Target == GLSL && usesStorageResource) { std::string key = "#version 330"; - vsText.replace(vsText.find(key), key.length(), "#version 430"); + std::size_t idx = vsText.find(key); + + if (idx != std::string::npos) + vsText.replace(idx, key.length(), "#version 430"); } else if (info.Target == ESSL && usesStorageResource) { std::string key = "#version 300"; - vsText.replace(vsText.find(key), key.length(), "#version 310"); + std::size_t idx = vsText.find(key); + + if (idx != std::string::npos) + vsText.replace(idx, key.length(), "#version 310"); } std::string fsText = fsCompiler->compile(); @@ -456,12 +462,18 @@ CompilationResult *CompileVertexFragment(const CrossCompileInfo &info) if (info.Target == GLSL && usesStorageResource) { std::string key = "#version 330"; - fsText.replace(vsText.find(key), key.length(), "#version 430"); + std::size_t idx = fsText.find(key); + + if (idx != std::string::npos) + fsText.replace(idx, key.length(), "#version 430"); } else if (info.Target == ESSL && usesStorageResource) { std::string key = "#version 300"; - fsText.replace(vsText.find(key), key.length(), "#version 310"); + std::size_t idx = fsText.find(key); + + if (idx != std::string::npos) + fsText.replace(idx, key.length(), "#version 310"); } CompilationResult *result = new CompilationResult();