[Bugfix] UIDrawable: Silent failure when RenderTexture creation fails #227

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

Summary

enableRenderTexture() silently fails if sf::RenderTexture::create() fails (e.g., out of VRAM, size too large). No error is reported and subsequent code may assume the texture exists.

Root Cause

In UIDrawable.cpp lines 411-425:

void UIDrawable::enableRenderTexture(unsigned int width, unsigned int height) {
    if (!render_texture || render_texture->getSize().x != width || ...) {
        render_texture = std::make_unique<sf::RenderTexture>();
        if (!render_texture->create(width, height)) {
            render_texture.reset();
            use_render_texture = false;
            return;  // ← Silent failure, no logging or error
        }
        render_sprite.setTexture(render_texture->getTexture());
    }
    use_render_texture = true;
    render_dirty = true;
}

Symptoms

  • Large frames with clip_children=True may silently fall back to unclipped rendering
  • No indication to user/developer that GPU resources were exhausted
  • Difficult to debug rendering inconsistencies

Proposed Fix

Add logging and/or return value:

bool UIDrawable::enableRenderTexture(unsigned int width, unsigned int height) {
    // ...
    if (!render_texture->create(width, height)) {
        std::cerr << "Warning: Failed to create RenderTexture (" 
                  << width << "x" << height << ")" << std::endl;
        render_texture.reset();
        use_render_texture = false;
        return false;
    }
    // ...
    return true;
}

Consider also exposing this to Python for debugging (frame.render_texture_active property?).

## Summary `enableRenderTexture()` silently fails if `sf::RenderTexture::create()` fails (e.g., out of VRAM, size too large). No error is reported and subsequent code may assume the texture exists. ## Root Cause In `UIDrawable.cpp` lines 411-425: ```cpp void UIDrawable::enableRenderTexture(unsigned int width, unsigned int height) { if (!render_texture || render_texture->getSize().x != width || ...) { render_texture = std::make_unique<sf::RenderTexture>(); if (!render_texture->create(width, height)) { render_texture.reset(); use_render_texture = false; return; // ← Silent failure, no logging or error } render_sprite.setTexture(render_texture->getTexture()); } use_render_texture = true; render_dirty = true; } ``` ## Symptoms - Large frames with `clip_children=True` may silently fall back to unclipped rendering - No indication to user/developer that GPU resources were exhausted - Difficult to debug rendering inconsistencies ## Proposed Fix Add logging and/or return value: ```cpp bool UIDrawable::enableRenderTexture(unsigned int width, unsigned int height) { // ... if (!render_texture->create(width, height)) { std::cerr << "Warning: Failed to create RenderTexture (" << width << "x" << height << ")" << std::endl; render_texture.reset(); use_render_texture = false; return false; } // ... return true; } ``` Consider also exposing this to Python for debugging (`frame.render_texture_active` property?).
john closed this issue 2026-02-09 12:47:41 +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#227
No description provided.