Strange crash since new build

Started by Nafffen, 04 October 2023, 19:44:11


I face a crash bug since I went from build baf9c5e73935453e357a9e8bda8df86bb83ed3e0 to last build (789aca88603268af99a416af6c0f11be1d03a7b8)
I cant manage to see where the bug is, this is the callstack :!tgui::Container::processKeyPressEvent(tgui::Container * const this, tgui::Event::KeyEvent event) (/home/user/Desktop/dev/fc/external_deps/TGUI/src/Container.cpp:1252)!tgui::BackendGui::handleEvent(tgui::BackendGui * const this, tgui::Event event) (/home/user/Desktop/dev/fc/external_deps/TGUI/src/Backend/Window/BackendGui.cpp:181)!tgui::BackendGuiSFML::handleEvent(tgui::BackendGuiSFML * const this, sf::Event sfmlEvent) (/home/user/Desktop/dev/fc/external_deps/TGUI/src/Backend/Window/SFML/BackendGuiSFML.cpp:219)
GuiManager::event(GuiManager * const this, const sf::Event & event) (/home/user/Desktop/dev/fc/fc_game/src/Graphics/GuiManager.cpp:88)
SceneLogin::loop(SceneLogin * const this) (/home/user/Desktop/dev/fc/fc_game/src/Scenes/SceneLogin.cpp:169)
Application::run(Application * const this) (/home/user/Desktop/dev/fc/fc_game/src/Core/Application.cpp:259)
main() (/home/user/Desktop/dev/fc/fc_game/src/Core/Application.cpp:56)

And vsc debugger told me there is a segmentation fault in the line :
            const bool bHandled = m_focusedWidget->canHandleKeyPress(event); // TGUI_NEXT: Have keyPressed return a bool
m_focusedWidget seems to be nullptr (I dont understand that because there is a checking if just before)

The idea of my code was to lunch a callback when user presses enter when focusing an editbox.
In the Constructor of my object :
    m_editBoxEmailSignIn->onReturnKeyPress(&SceneLogin::trySignIn, this);

void SceneLogin::trySignIn(){
    //TODO: remove backdoor
    if(m_editBoxEmailSignIn->getText() == "dev"){
        this->m_continueLoop = false;
        this->m_appli.launchSceneBase({0, 0});


    //bla bla bla

The strange thing is the crash only appears when the above condition if(m_editBoxEmailSignIn->getText() == "dev"){ is true, if user doesnt input "dev", then the program doesnt crash.

I am not even sure if this is about my code or something, could you give me your thoughts ?


This looks like a bug in TGUI. I'm assuming either launchAllLoading or launchSceneBase causes the focused widget to change. Your callback function gets called at the "m_focusedWidget->keyPressed" line, and probably does something that sets m_focusedWidget to a nullptr. After that, the "m_focusedWidget->canHandleKeyPress" line gets executed, but by that time m_focusedWidget is a nullptr.

So I need to add another check inbetween the keyPressed and canHandleKeyPress line to deal with this case.
Update: The issue has been fixed in the latest version.