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

Fix crash when loading huge image #3775

Merged
merged 3 commits into from
Oct 10, 2023
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
18 changes: 18 additions & 0 deletions crates/re_renderer/src/resource_managers/texture_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ pub enum TextureCreationError {
#[error("Texture with debug label {0:?} has zero width or height!")]
ZeroSize(DebugLabel),

#[error("Texture was {width}x{height}, larger than the max of {max_texture_dimension_2d}")]
TooLarge {
width: u32,
height: u32,
max_texture_dimension_2d: u32,
},

#[error(
"Texture with debug label {label:?} has a format {format:?} that data can't be transferred to!"
)]
Expand Down Expand Up @@ -339,6 +346,17 @@ impl TextureManager2D {
return Err(TextureCreationError::ZeroSize(creation_desc.label.clone()));
}

let max_texture_dimension_2d = device.limits().max_texture_dimension_2d;
if creation_desc.width > max_texture_dimension_2d
|| creation_desc.height > max_texture_dimension_2d
{
return Err(TextureCreationError::TooLarge {
width: creation_desc.width,
height: creation_desc.height,
max_texture_dimension_2d,
});
}

let size = wgpu::Extent3d {
width: creation_desc.width,
height: creation_desc.height,
Expand Down
2 changes: 1 addition & 1 deletion crates/re_space_view_spatial/src/parts/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn to_textured_rect(
})
}
Err(err) => {
re_log::error_once!("Failed to create texture from tensor for {debug_name:?}: {err}");
re_log::error_once!("Failed to create texture for {debug_name:?}: {err}");
None
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/re_viewer_context/src/gpu_bridge/tensor_to_gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn color_tensor_to_gpu(
height,
})
})
.map_err(|err| anyhow::anyhow!("Failed to create texture for color tensor: {err}"))?;
.map_err(|err| anyhow::anyhow!("{err}"))?;

let texture_format = texture_handle.format();

Expand Down Expand Up @@ -215,7 +215,7 @@ pub fn class_id_tensor_to_gpu(
let main_texture_handle = try_get_or_create_texture(render_ctx, hash(tensor_path_hash), || {
general_texture_creation_desc_from_tensor(debug_name, tensor)
})
.map_err(|err| anyhow::anyhow!("Failed to create texture for class id tensor: {err}"))?;
.map_err(|err| anyhow::anyhow!("{err}"))?;

Ok(ColormappedTexture {
texture: main_texture_handle,
Expand Down
Loading