FyroxEngine/Fyrox · error
only rectangle textures can be used as render target!
Error message
only rectangle textures can be used as render target!
What it means
The renderer computes the framebuffer size from the render-target texture; only TextureKind::Rectangle carries usable width/height for this purpose. Any other texture kind panics because it cannot serve as a render target.
Solutions
- Create render-target textures with TextureKind::Rectangle { width, height }
- Validate the texture kind before assigning it as a render target
- Use RenderTarget::screen() or None when the window backbuffer is intended
Example fix
// before
let rt = Texture::new(ctx, TextureDescriptor { kind: TextureKind::D2 { width: 512, height: 512 }, ..});
// after
let rt = Texture::new(ctx, TextureDescriptor { kind: TextureKind::Rectangle { width: 512, height: 512 }, ..}); Defensive patterns
Strategy: validation
Validate before calling
assert!(matches!(rt.data_ref().kind(), TextureKind::Rectangle{..})); Type guard
fn as_rect_kind(k: &TextureKind) -> Option<(u32,u32)> { if let TextureKind::Rectangle{width,height} = k { Some((*width,*height)) } else { None } } Prevention
- Use TextureKind::Rectangle for all render targets
- Centralize render-target creation in one validated helper
- Never assign sampled 2D textures as render targets
When it happens
Trigger: Setting a camera/scene render target to a texture with kind D2, Cube, or Volume and running a render pass.
Common situations: Creating offscreen render targets with the wrong TextureKind; reusing regular 2D sampled textures as render targets; following outdated tutorials.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- only rectangle textures can be used as render target!
- Invalid pixel position
- Height data type error
- Missing hole mask texture
- Pixel types must match!
AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10).
Data as JSON: /api/errors/6487df2190599bcb.
Report an issue: GitHub.
Appendix: source
Thrown at fyrox-impl/src/renderer/mod.rs:1311
let backbuffer_width = self.frame_size.0 as f32;
let backbuffer_height = self.frame_size.1 as f32;
let window_viewport = Rect::new(0, 0, self.frame_size.0 as i32, self.frame_size.1 as i32);
let frame_size = scene
.rendering_options
.render_target
.as_ref()
.map_or_else(
// Use either backbuffer size
|| Vector2::new(backbuffer_width, backbuffer_height),
// Or framebuffer size
|rt| {
if let TextureKind::Rectangle { width, height } = rt.data_ref().kind() {
Vector2::new(width as f32, height as f32)
} else {
panic!("only rectangle textures can be used as render target!")
}
},
)
// Clamp to [1.0; infinity] range.
.sup(&Vector2::new(1.0, 1.0));
let scene_render_data = match self.scene_data_map.entry(scene_handle) {
Entry::Occupied(entry) => {
let render_data = entry.into_mut();
recreate_render_data_if_needed(
scene_handle,
&*self.server,
&mut render_data.scene_data,
frame_size,
FrameTextureKind::Rectangle,
)?;
render_data
}View on GitHub (pinned to 76c91aad8e)