bevyengine/bevy · error · ViewportConversionError
found NaN while computing NDC
Error message
found NaN while computing NDC
What it means
ViewportConversionError::NaNInNDC: the transformation from world space to normalized device coordinates produced NaN components, typically because the camera's view-projection matrix contains NaNs (degenerate transform, zero-scale, or invalid projection settings).
Source
Thrown at crates/bevy_camera/src/camera.rs:355
/// - it references a [`Window`](RenderTarget::Window) entity that doesn't exist or doesn't actually have a `Window` component,
/// - it references an [`Image`](RenderTarget::Image) that doesn't exist (invalid handle),
/// - it references a [`TextureView`](RenderTarget::TextureView) that doesn't exist (invalid handle).
#[error("pre-computed size of viewport not available")]
NoViewportSize,
/// The computed coordinate was beyond the `Camera`'s near plane.
///
/// Only applicable when converting from world-space to viewport-space.
#[error("computed coordinate beyond `Camera`'s near plane")]
PastNearPlane,
/// The computed coordinate was beyond the `Camera`'s far plane.
///
/// Only applicable when converting from world-space to viewport-space.
#[error("computed coordinate beyond `Camera`'s far plane")]
PastFarPlane,
/// The Normalized Device Coordinates could not be computed because the `camera_transform`, the
/// `world_position`, or the projection matrix defined by [`Projection`](super::projection::Projection)
/// contained `NAN` (see [`world_to_ndc`][Camera::world_to_ndc] and [`ndc_to_world`][Camera::ndc_to_world]).
#[error("found NaN while computing NDC")]
InvalidData,
}
/// The defining [`Component`] for camera entities,
/// storing information about how and what to render through this camera.
///
/// The [`Camera`] component is added to an entity to define the properties of the viewpoint from
/// which rendering occurs. It defines the position of the view to render, the projection method
/// to transform the 3D objects into a 2D image, as well as the render target into which that image
/// is produced.
///
/// Note that a [`Camera`] needs a `CameraRenderGraph` to render anything.
/// This is typically provided by adding a [`Camera2d`] or [`Camera3d`] component,
/// but custom render graphs can also be defined. Inserting a [`Camera`] with no render
/// graph will emit an error at runtime.
///
/// [`Camera2d`]: crate::Camera2d
/// [`Camera3d`]: crate::Camera3dView on GitHub (pinned to 396ca72708)
Solutions
- Check the camera and any parent transforms for NaN/zero-scale values
- Validate projection parameters (non-zero near/far, valid aspect)
- Avoid converting points exactly at the camera origin
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/bevy_camera/src/camera.rs:355 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/1cf6531f1b8b627a.
Report an issue: GitHub.