Skip to content

Commit 4665f7b

Browse files
better error messages for shader compilation errors
1 parent d6bc414 commit 4665f7b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

crates/bevy_render/src/pipeline/pipeline_compiler.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl PipelineCompiler {
143143
&specialized_descriptor.shader_stages.vertex,
144144
&pipeline_specialization.shader_specialization,
145145
)
146-
.unwrap();
146+
.unwrap_or_else(|e| panic_shader_error(e));
147147
specialized_descriptor.shader_stages.vertex = specialized_vertex_shader.clone_weak();
148148
let mut specialized_fragment_shader = None;
149149
specialized_descriptor.shader_stages.fragment = specialized_descriptor
@@ -158,7 +158,7 @@ impl PipelineCompiler {
158158
fragment,
159159
&pipeline_specialization.shader_specialization,
160160
)
161-
.unwrap();
161+
.unwrap_or_else(|e| panic_shader_error(e));
162162
specialized_fragment_shader = Some(shader.clone_weak());
163163
shader
164164
});
@@ -356,3 +356,10 @@ impl PipelineCompiler {
356356
Ok(())
357357
}
358358
}
359+
360+
fn panic_shader_error(error: ShaderError) -> ! {
361+
let msg = error.to_string();
362+
let msg = msg.trim_end().trim_end_matches("Debug log:"); // if this matches, then there wasn't a debug log anyways
363+
let msg = msg.trim_end();
364+
panic!("{}\n", msg);
365+
}

crates/bevy_render/src/shader/shader.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ pub enum ShaderStage {
2424
#[derive(Error, Debug)]
2525
pub enum ShaderError {
2626
/// Shader compilation error.
27-
#[error("Shader compilation error: {0}")]
27+
#[error("Shader compilation error:\n{0}")]
2828
Compilation(String),
2929

3030
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
3131
/// shaderc error.
32-
#[error("shaderc error")]
32+
#[error("shaderc error: {}")]
3333
ShaderC(#[from] shaderc::Error),
3434

3535
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]

0 commit comments

Comments
 (0)