Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SFML 2.5] sf::RenderWindow::setTitle crashes in main loop  (Read 2186 times)

0 Members and 1 Guest are viewing this topic.

Khastor

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
[SFML 2.5] sf::RenderWindow::setTitle crashes in main loop
« on: July 21, 2019, 06:38:21 pm »
Hi !

I've not been using the SFML for a couple of years, but yesterday I've decided to get back to it. I've reinstalled everything from scratch on my Ubuntu : SFML 2.5 source code + dependencies (development packages), and I have compiled the SFML for dynamic/static and debug/release targets without any problem, just like described in the installation tutorial. I am able to compile and run the tutorial's example program.

Now, my issue is that when I try to change a RenderWindow's title in my main program's loop, my laptop irremediably freezes... I've tested Debug and Release configurations, both end up crashing and not even showing the window to the screen. What is funny is that I don't run into this issue if I change the window's title before the main loop. So the issue seems related to setTitle being called in this particular context.

Code to reproduce the issue :

#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "Test");
    sf::Clock clock;
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
        }
        float fps = 1.0f / clock.getElapsedTime().asSeconds();
        window.setTitle("FPS: " + std::to_string(fps));

        window.clear();
        window.display();
    }
    return 0;
}
 

CMakeLists :

cmake_minimum_required(VERSION 3.14)
project(TestProject)

set(CMAKE_CXX_STANDARD 14)

find_package(SFML 2.5 COMPONENTS graphics window system REQUIRED)

add_executable(TestProject src/main.cpp)
target_link_libraries(TestProject sfml-graphics sfml-window sfml-system)
 

Note : i had libsfml-dev previously installed (from apt-get), but as I realized it wasn't the latest version, I removed it (with apt remove) before I built SFML 2.5 from sources...

I am not sure whether my issue is related to my installation of the SFML, or to the SFML itself... or to my build configuration ?

Thank you for your time.

Yanson

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: [SFML 2.5] sf::RenderWindow::setTitle crashes in main loop
« Reply #1 on: July 29, 2019, 06:59:43 pm »
I don't think the windows title is meant to be updated this much.

#include <SFML/Graphics.hpp>
#include <string>
#include <iostream>

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "Test");
    sf::Clock clock;
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
        }
        float fps = 1.0f / clock.getElapsedTime().asSeconds();
        window.setTitle("FPS: " + std::to_string(fps));
        sf::sleep(sf::seconds(1));
        window.clear();
        window.display();
    }
    return 0;
}

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: [SFML 2.5] sf::RenderWindow::setTitle crashes in main loop
« Reply #2 on: July 31, 2019, 10:33:13 am »
Even if it isn't meant to, it shouldn't crash.

What's the callstack?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Khastor

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: [SFML 2.5] sf::RenderWindow::setTitle crashes in main loop
« Reply #3 on: July 31, 2019, 07:20:30 pm »
Thanks for the answers.

Even if it isn't meant to, it shouldn't crash.

I totally agree with (both of) you. The thing is, the program doesn't really crash, I'm sorry my first message was misleading. Somehow, the window doesn't show up and my GUI is frozen (I'm forced to restart my laptop after this), but I investigated a little more and it turns out that the code in the main loop still runs while everything is frozen !

If I run the code below, my GUI freezes for 5 seconds, then the program terminates normally :

#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>

int main()
{
    sf::RenderWindow window(sf::VideoMode(640, 480), "test");
    sf::Clock clock;
    sf::Clock killer;
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
        }
        std::string fps = std::to_string(1.0f / clock.restart().asSeconds());
        window.setTitle("FPS: " + fps);

        if(killer.getElapsedTime().asSeconds() > 5.0f)
        {
            window.close();
        }

        window.clear();
        window.display();
    }
    return 0;
}
 

When I debug the program step by step, everything runs just fine.
I don't really see how I could get a relevant callstack ?

I have the feeling that my program simply keeps spamming the windows manager (or whatever it is), and prevents it from doing anything else that changing the window's title, hence the freeze. I think I may just set a framerate limit or vsync and forget about this.

What do you think ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: [SFML 2.5] sf::RenderWindow::setTitle crashes in main loop
« Reply #4 on: August 02, 2019, 09:56:22 am »
Ah okay, I guess the system could potentially lock up from spamming, but that would be the first time I hear of this.
To me this sounds more like a third-party issue, e.g. an anti-virus software or some other odd system application...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Khastor

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: [SFML 2.5] sf::RenderWindow::setTitle crashes in main loop
« Reply #5 on: August 03, 2019, 05:52:40 pm »
Hm okay, the only third-party I can think of would be Arc Theme, but I still have the issue when I turn it off... I posted here because I was afraid there was a problem with my SFML installation, but as it doesn't seem to be case, let's consider this topic Resolved !

 

anything