[Bugfix] UIFrame: Zero-size frame with clip_children causes inconsistent state #226

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

Summary

If clip_children=True is set on a Frame with size (0, 0), the RenderTexture creation is skipped but the state becomes inconsistent.

Root Cause

In UIFrame::render() lines 118-125:

if (!use_render_texture) {
    auto size = box.getSize();
    if (size.x > 0 && size.y > 0) {
        enableRenderTexture(static_cast<unsigned int>(size.x),
                          static_cast<unsigned int>(size.y));
    }
    // ← No else branch: use_render_texture stays false
}

And in UIFrame::init() lines 632-634:

if (cache_subtree && w > 0 && h > 0) {
    self->data->enableRenderTexture(...);
}

Problem Scenarios

  1. Create Frame with clip_children=True, size=(0,0)
  2. RenderTexture not created (size check fails)
  3. Later resize Frame to (100, 100)
  4. render() runs, but use_render_texture is already being checked...
  5. State may be inconsistent depending on render order

Proposed Fix

Either:

  1. Defer all texture creation to render-time with proper size validation
  2. Re-check and create texture when size changes (already partially done in set_float_member for w/h)
  3. Disallow clip_children=True on zero-size frames (raise error)
## Summary If `clip_children=True` is set on a Frame with size `(0, 0)`, the RenderTexture creation is skipped but the state becomes inconsistent. ## Root Cause In `UIFrame::render()` lines 118-125: ```cpp if (!use_render_texture) { auto size = box.getSize(); if (size.x > 0 && size.y > 0) { enableRenderTexture(static_cast<unsigned int>(size.x), static_cast<unsigned int>(size.y)); } // ← No else branch: use_render_texture stays false } ``` And in `UIFrame::init()` lines 632-634: ```cpp if (cache_subtree && w > 0 && h > 0) { self->data->enableRenderTexture(...); } ``` ## Problem Scenarios 1. Create Frame with `clip_children=True, size=(0,0)` 2. RenderTexture not created (size check fails) 3. Later resize Frame to `(100, 100)` 4. `render()` runs, but `use_render_texture` is already being checked... 5. State may be inconsistent depending on render order ## Proposed Fix Either: 1. Defer all texture creation to render-time with proper size validation 2. Re-check and create texture when size changes (already partially done in `set_float_member` for w/h) 3. Disallow `clip_children=True` on zero-size frames (raise error)
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#226
No description provided.