Skip to content

Commit

Permalink
Merge pull request #1 from jamylak/errors-on-hot-reload
Browse files Browse the repository at this point in the history
make sure errors in shader compilation on hot reload don't segfault
  • Loading branch information
jamylak authored Aug 18, 2024
2 parents 1d9279a + 20a59fc commit 3417abe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/sdf_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ void SDFRenderer::setupRenderContext() {

void SDFRenderer::createPipeline() {
pipelineLayout = vkutils::createPipelineLayout(logicalDevice);
auto fragSpirvPath = shader_utils::compile(fragShaderPath, useToyTemplate);
std::filesystem::path fragSpirvPath;
try {
fragSpirvPath = shader_utils::compile(fragShaderPath, useToyTemplate);
} catch (const std::runtime_error &e) {
// An error occured while compiling the shader
// This can happen while doing live edits
// Just try find the old one until the error is fixed
fragSpirvPath = fragShaderPath;
fragSpirvPath.replace_extension(".spv");
}
fragShaderModule =
vkutils::createShaderModule(logicalDevice, fragSpirvPath);
pipeline = vkutils::createGraphicsPipeline(
Expand Down
5 changes: 5 additions & 0 deletions src/shader_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ std::filesystem::path compile(const std::string &shaderFilename,
spdlog::info("Shader linked: {}", linked);
spdlog::info("Program info log: {}", program.getInfoLog());

if (!linked) {
spdlog::error("Failed to link shader program");
throw std::runtime_error("Failed to link shader program");
}

// Now save SPIR-V binary to a file
std::vector<unsigned int> spirv;
spv::SpvBuildLogger logger{};
Expand Down

0 comments on commit 3417abe

Please sign in to comment.