Skip to content

Commit 5330b01

Browse files
authored
Make Skybox not break rendering if its image is default or 2D. (#23689)
# Objective - Partially addresses #23688. - Gives advice to users who accidentally create an invalid `Skybox`. - Prevents rendering from totally breaking in that case. ## Solution If the image is detected to be invalid, have `prepare_skybox_bind_groups` ignore it (and warn once). ## Testing Manually tested that `examples/3d/skybox.rs` works if the initial skybox has the default image. If there’s a good way to programmatically test things like this, let me know — I didn’t see any similar tests to emulate.
1 parent 8b5a3b8 commit 5330b01

File tree

1 file changed

+24
-0
lines changed
  • crates/bevy_core_pipeline/src/skybox

1 file changed

+24
-0
lines changed

crates/bevy_core_pipeline/src/skybox/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use bevy_ecs::{
1010
};
1111
use bevy_image::BevyDefault;
1212
use bevy_light::Skybox;
13+
use bevy_log::warn_once;
1314
use bevy_math::Mat4;
1415
use bevy_render::{
1516
extract_component::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin},
@@ -232,6 +233,7 @@ fn prepare_skybox_bind_groups(
232233
view_uniforms.uniforms.binding(),
233234
skybox_uniforms.binding(),
234235
) && let Some(image) = images.get(image_handle)
236+
&& sanity_check_skybox_image_and_warn(entity, skybox, image)
235237
{
236238
let bind_group = render_device.create_bind_group(
237239
"skybox_bind_group",
@@ -252,3 +254,25 @@ fn prepare_skybox_bind_groups(
252254
}
253255
}
254256
}
257+
258+
fn sanity_check_skybox_image_and_warn(entity: Entity, skybox: &Skybox, image: &GpuImage) -> bool {
259+
let texture_view_dimension: Option<TextureViewDimension> = image
260+
.texture_view_descriptor
261+
.as_ref()
262+
.and_then(|desc| desc.dimension);
263+
let dimension_ok = texture_view_dimension == Some(TextureViewDimension::Cube);
264+
if !dimension_ok {
265+
// The texture view is not a cubemap and will fail validation if rendered.
266+
// In this case, we ignore the skybox so as not to break rendering.
267+
//
268+
// There are other possible misconfigurations which will fail and which we do not
269+
// catch here, but this is a common mistake (passing an unaltered 2D image to `Skybox`).
270+
warn_once!(
271+
"skybox {entity}'s image {image:?} has texture view dimension \
272+
{texture_view_dimension:?}, but it must be TextureViewDimension::Cube \
273+
to render a skybox",
274+
image = skybox.image
275+
);
276+
}
277+
dimension_ok
278+
}

0 commit comments

Comments
 (0)