bevyengine/bevy · error
Failed to update PerspectiveProjection: width and height mus
Error message
Failed to update PerspectiveProjection: width and height must be positive, non-zero values
What it means
Raised by PerspectiveProjection::update when the viewport or render-target dimensions passed in are zero or negative, making the computed aspect-dependent projection terms (frustum widths/heights) invalid. The projection matrix cannot be sensibly built from such dimensions.
Source
Thrown at crates/bevy_camera/src/projection.rs:391
let x = (2.0 * self.near) / (right_prime - left_prime);
let y = (2.0 * self.near) / (top_prime - bottom_prime);
let a = (right_prime + left_prime) / (right_prime - left_prime);
let b = (top_prime + bottom_prime) / (top_prime - bottom_prime);
let mut matrix = Mat4::from_cols(
Vec4::new(x, 0.0, 0.0, 0.0),
Vec4::new(0.0, y, 0.0, 0.0),
Vec4::new(a, b, 0.0, -1.0),
Vec4::new(0.0, 0.0, self.near, 0.0),
);
self.adjust_perspective_matrix_for_clip_plane(&mut matrix);
matrix
}
fn update(&mut self, width: f32, height: f32) {
self.aspect_ratio = AspectRatio::try_new(width, height)
.expect("Failed to update PerspectiveProjection: width and height must be positive, non-zero values")
.ratio();
}
fn far(&self) -> f32 {
self.far
}
fn get_frustum_corners(&self, z_near: f32, z_far: f32) -> [Vec3A; 8] {
let tan_half_fov = ops::tan(self.fov / 2.);
let a = z_near.abs() * tan_half_fov;
let b = z_far.abs() * tan_half_fov;
let aspect_ratio = self.aspect_ratio;
// NOTE: These vertices are in the specific order required by [`calculate_cascade`].
[
Vec3A::new(a * aspect_ratio, -a, z_near), // bottom right
Vec3A::new(a * aspect_ratio, a, z_near), // top right
Vec3A::new(-a * aspect_ratio, a, z_near), // top left
Vec3A::new(-a * aspect_ratio, -a, z_near), // bottom leftView on GitHub (pinned to 396ca72708)
Solutions
- Ensure the window/render target has non-zero width and height before the camera renders
- Delay camera activation until the window is sized
- Guard code that resizes targets to zero (minimized window)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/bevy_camera/src/projection.rs:391 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of bevyengine/bevy@396ca72708 (2026-08-20).
Data as JSON: /api/errors/155829e1697c66b7.
Report an issue: GitHub.