[Bugfix] UIFrame: box.setPosition(0,0) corrupts position when using clip_children #223

Closed
opened 2026-01-22 15:48:53 +00:00 by john · 0 comments
Owner

Summary

When clip_children=True, UIFrame::render() sets box.setPosition(0, 0) to render the box at the origin of the RenderTexture, but never restores box to its original position. This corrupts the position state and causes incorrect rendering.

Root Cause

In UIFrame.cpp lines 128-163:

if (use_render_texture && render_dirty) {
    render_texture->clear(sf::Color::Transparent);

    box.setPosition(0, 0);  // ← Sets box to origin for texture
    render_texture->draw(box);
    
    // ... children rendered ...
    render_dirty = false;
}

if (use_render_texture) {
    render_sprite.setPosition(offset + box.getPosition());  // ← box.getPosition() is (0,0)!
    target.draw(render_sprite);
}

Symptoms

  1. Frame appears at wrong position when clip_children=True
  2. Toggling clip_children off causes frame to appear at origin + offset
  3. Modifying frame.x or frame.y "fixes" the position (because onPositionChanged() restores box)

Proposed Fix

Use position (the canonical source of truth) instead of box.getPosition():

render_sprite.setPosition(offset + position);

Or restore box after texture rendering:

box.setPosition(0, 0);
render_texture->draw(box);
box.setPosition(position);  // ← Restore

Option 1 is cleaner since position is the authoritative value.

## Summary When `clip_children=True`, `UIFrame::render()` sets `box.setPosition(0, 0)` to render the box at the origin of the RenderTexture, but **never restores** `box` to its original position. This corrupts the position state and causes incorrect rendering. ## Root Cause In `UIFrame.cpp` lines 128-163: ```cpp if (use_render_texture && render_dirty) { render_texture->clear(sf::Color::Transparent); box.setPosition(0, 0); // ← Sets box to origin for texture render_texture->draw(box); // ... children rendered ... render_dirty = false; } if (use_render_texture) { render_sprite.setPosition(offset + box.getPosition()); // ← box.getPosition() is (0,0)! target.draw(render_sprite); } ``` ## Symptoms 1. Frame appears at wrong position when `clip_children=True` 2. Toggling `clip_children` off causes frame to appear at origin + offset 3. Modifying `frame.x` or `frame.y` "fixes" the position (because `onPositionChanged()` restores `box`) ## Proposed Fix Use `position` (the canonical source of truth) instead of `box.getPosition()`: ```cpp render_sprite.setPosition(offset + position); ``` Or restore box after texture rendering: ```cpp box.setPosition(0, 0); render_texture->draw(box); box.setPosition(position); // ← Restore ``` Option 1 is cleaner since `position` is the authoritative value.
john closed this issue 2026-01-23 03:56:05 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
john/McRogueFace#223
No description provided.