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

[Merged by Bors] - Error message improvements for shader compilation/gltf loading #1786

Closed
Closed
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
8 changes: 4 additions & 4 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ use crate::{Gltf, GltfNode};
pub enum GltfError {
#[error("unsupported primitive mode")]
UnsupportedPrimitive { mode: Mode },
#[error("invalid GLTF file")]
#[error("invalid GLTF file: {0}")]
Gltf(#[from] gltf::Error),
#[error("binary blob is missing")]
MissingBlob,
#[error("failed to decode base64 mesh data")]
Base64Decode(#[from] base64::DecodeError),
#[error("unsupported buffer format")]
BufferFormatUnsupported,
#[error("invalid image mime type")]
#[error("invalid image mime type: {0}")]
InvalidImageMimeType(String),
#[error("failed to load an image")]
#[error("{0}")]
ImageError(#[from] TextureError),
#[error("failed to load an asset path")]
#[error("failed to load an asset path: {0}")]
AssetIoError(#[from] AssetIoError),
}

Expand Down
13 changes: 11 additions & 2 deletions crates/bevy_render/src/pipeline/pipeline_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl PipelineCompiler {
&specialized_descriptor.shader_stages.vertex,
&pipeline_specialization.shader_specialization,
)
.unwrap();
.unwrap_or_else(|e| panic_shader_error(e));
specialized_descriptor.shader_stages.vertex = specialized_vertex_shader.clone_weak();
let mut specialized_fragment_shader = None;
specialized_descriptor.shader_stages.fragment = specialized_descriptor
Expand All @@ -158,7 +158,7 @@ impl PipelineCompiler {
fragment,
&pipeline_specialization.shader_specialization,
)
.unwrap();
.unwrap_or_else(|e| panic_shader_error(e));
specialized_fragment_shader = Some(shader.clone_weak());
shader
});
Expand Down Expand Up @@ -356,3 +356,12 @@ impl PipelineCompiler {
Ok(())
}
}

fn panic_shader_error(error: ShaderError) -> ! {
let msg = error.to_string();
let msg = msg
.trim_end()
.trim_end_matches("Debug log:") // if this matches, then there wasn't a debug log anyways
.trim_end();
panic!("{}\n", msg);
}
4 changes: 2 additions & 2 deletions crates/bevy_render/src/shader/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub enum ShaderStage {
#[derive(Error, Debug)]
pub enum ShaderError {
/// Shader compilation error.
#[error("Shader compilation error: {0}")]
#[error("Shader compilation error:\n{0}")]
Compilation(String),

#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
/// shaderc error.
#[error("shaderc error")]
#[error("shaderc error: {}")]
ShaderC(#[from] shaderc::Error),

#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_render/src/texture/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub enum TextureError {
InvalidImageMimeType(String),
#[error("invalid image extension")]
InvalidImageExtension(String),
#[error("failed to load an image")]
#[error("failed to load an image: {0}")]
ImageError(#[from] image::ImageError),
}

Expand Down