Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sure errors in shader compilation on hot reload don't segfault #1

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading