CanvasSFML rendering frozen

Started by InvisibleShoe, 16 December 2024, 10:07:17

InvisibleShoe

Hi
I have my game screen setup as below:

    auto gui = world.get_mut<Tag::GuiRoot>();
    auto hudRoot = tgui::HorizontalLayout::create();

// LEFT WIDGETS

    auto leftPanel = tgui::VerticalLayout::create();
    leftPanel->setFocusable(false);

    auto topLeft = tgui::Panel::create();
    topLeft->getRenderer()->setBackgroundColor(sf::Color::Green);
    leftPanel->add(topLeft);

    auto canvas = tgui::CanvasSFML::create();
    leftPanel->add(canvas, "GameCanvas");
    world.set( Tag::GameCanvas{canvas} );

    leftPanel->setRatio(canvas, 15.0f);

    auto bottomLeft = tgui::Panel::create();
    bottomLeft->getRenderer()->setBackgroundColor(sf::Color::Blue);
    leftPanel->add(bottomLeft);

    hudRoot->add(leftPanel, "LeftPanel");

// RIGHT WIDGETS
    auto rightPanel = tgui::VerticalLayout::create();
    // rightPanel->setFocusable(false);

    auto topRight = tgui::Panel::create();
    topRight->getRenderer()->setBackgroundColor(sf::Color::Green);
    rightPanel->add(topRight);

    auto bottomRight = tgui::Panel::create();
    bottomRight->getRenderer()->setBackgroundColor(sf::Color::Blue);
    rightPanel->add(bottomRight);

    hudRoot->add(rightPanel, "RightPanel");
    hudRoot->setRatio(rightPanel, 0.3f);

    hudRoot->setVisible(false);

    gui->gui->add(hudRoot, "HudRoot");

The render process looks similar to:

canvas->clear(sf::Color::Black);
window->clear(sf::Color::White);

// render sprites to canvas

canvas->display();

gui->draw();

window->display()


Canvas rendering works fine on startup but as soon as I click on a gui widget(eg the right panel above) the canvas stops redrawing and won't unfreeze.
If I disable focus on the widget then the canvas stops freezing, so it seems to be an issue with widgets stealing focus from the canvas.
I've run my code in debug with breakpoints and the sprite rendering system is running in the background but the window stops responding to input and the canvas rendering stops.

Can anyone help with this? I was hoping to embed canvas widgets in a few places in a similar manner.

Cheers

InvisibleShoe

Did some more investigating and its a problem with the gui capturing input events before they can get to the game controller.

Going to have to think about this one.