FyroxEngine/Fyrox · error

Cannot add window to split tile

Error message

Cannot add window to split tile

What it means

Tile::plus_window can only add a window to a tile that is Empty, a single Window, or MultiWindow. If the tile is a Split (contains child tiles), there is no defined place to put the window, so the library panics deliberately as an internal state violation.

Solutions

  1. Match on the tile and only call plus_window for Empty/Window/MultiWindow variants
  2. If the tile is a Split, add the window to one of its child tiles instead
  3. Track tile kind in your own layout state before mutating it

Example fix

// before
tile = tile.plus_window(window_handle);

// after
tile = match tile {
    Tile::Split { .. } => tile.with_content(...), // or add to a child tile
    _ => tile.plus_window(window_handle),
};
Defensive patterns

Strategy: type-guard

Validate before calling

if matches!(tile, Tile::Split { .. }) { panic-guard: handle split case separately }

Type guard

fn can_add_window(tile: &Tile) -> bool { !matches!(tile, Tile::Split { .. }) }

Try / catch

// Rust panics are not catchable here without catch_unwind; guard by matching variants before the call
match tile { Tile::Split { .. } => /* route to child */, _ => tile.plus_window(w) }

Prevention

When it happens

Trigger: Calling Tile::plus_window on a tile constructed via split_left_right/split_top_bottom (Tile::Split variant).

Common situations: Dock layout manipulation code that walks a tile tree adding windows without checking whether the tile is a split container; saving/restoring custom dock layouts programmatically.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of FyroxEngine/Fyrox@76c91aad8e (2026-09-10). Data as JSON: /api/errors/c25b29e47ff0bdd2. Report an issue: GitHub.

Appendix: source

Thrown at fyrox-ui/src/dock/tile.rs:112

        }
    }
    /// Construct a new tile that adds the given window to this tile.
    /// This tile must be either empty, a window, or a multiwindow, or else panic.
    pub fn plus_window(self, window: Handle<Window>) -> Self {
        match self {
            Self::Empty => Self::Window(window),
            Self::Window(handle) => Self::MultiWindow {
                index: 0,
                windows: vec![window, handle],
            },
            Self::MultiWindow { mut windows, .. } => {
                windows.push(window);
                Self::MultiWindow {
                    index: windows.len() as u32 - 1,
                    windows,
                }
            }
            _ => panic!("Cannot add window to split tile"),
        }
    }
    /// Construct a new tile that removes the given window from this tile.
    /// This tile must be either empty, a window, or a multiwindow, or else panic.
    /// If the window does not exist in this tile, then return self.
    pub fn minus_window(self, window: Handle<Window>) -> Self {
        match self {
            Self::Empty => Self::Empty,
            Self::Window(handle) => {
                if window == handle {
                    Self::Empty
                } else {
                    self
                }
            }
            Self::MultiWindow { index, mut windows } => {
                let current = windows.get(index as usize).copied();
                windows.retain(|h| h != &window);

View on GitHub (pinned to 76c91aad8e)