mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 12:13:25 +00:00
Return Error instead of panicking when reading invalid dds file (#16283)
# Objective Fixes #15928 ## Solution return Error instead of panic ## Testing I don't know if we need to add a test for this. It is pretty straightforward.
This commit is contained in:
parent
c29e67153b
commit
56a002b693
1 changed files with 4 additions and 1 deletions
|
@ -1,3 +1,5 @@
|
|||
//! [DirectDraw Surface](https://en.wikipedia.org/wiki/DirectDraw_Surface) functionality.
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
use bevy_utils::warn_once;
|
||||
use ddsfile::{Caps2, D3DFormat, Dds, DxgiFormat};
|
||||
|
@ -16,7 +18,8 @@ pub fn dds_buffer_to_image(
|
|||
is_srgb: bool,
|
||||
) -> Result<Image, TextureError> {
|
||||
let mut cursor = Cursor::new(buffer);
|
||||
let dds = Dds::read(&mut cursor).expect("Failed to parse DDS file");
|
||||
let dds = Dds::read(&mut cursor)
|
||||
.map_err(|error| TextureError::InvalidData(format!("Failed to parse DDS file: {error}")))?;
|
||||
let texture_format = dds_format_to_texture_format(&dds, is_srgb)?;
|
||||
if !supported_compressed_formats.supports(texture_format) {
|
||||
return Err(TextureError::UnsupportedTextureFormat(format!(
|
||||
|
|
Loading…
Reference in a new issue