SFML community forums

Help => Graphics => Topic started by: JAKUBW on June 23, 2017, 04:57:41 pm

Title: Stack overflow while creating sf::RenderTexture in other thread
Post by: JAKUBW on June 23, 2017, 04:57:41 pm
Hey

I try to create sf::RenderTexture object in std::thread method and it causes stack overflow.
My code:
#include <SFML/Graphics.hpp>
#include <thread>

int main()
{
        sf::RenderTexture texture;
        std::thread thread([]() {
                sf::RenderTexture t;
        });

        thread.join();
        return 0;
}
 
Without creating first texture it happens too.
#include <SFML/Graphics.hpp>
#include <thread>

int main()
{
        sf::RenderWindow window(sf::VideoMode(800, 600), "WINDOW");

        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        if (event.type == sf::Event::MouseButtonPressed)//crash when button is pressed
                        {
                                std::thread thread([]() {
                                        sf::RenderTexture t;
                                });
                        }
                }
                window.clear(sf::Color(50, 50, 50));
                window.display();
        }
        return 0;
}
 
but it doesn't crash with this code:
#include <SFML/Graphics.hpp>
#include <thread>

int main()
{
        std::thread thread([]() {
                sf::RenderTexture t;
        });
        thread.join();
        return 0;
}

How to solve this problem?

SFML 2.4.2
Microsoft Visual Studio Community 2015, Version 14
Title: Re: Stack overflow while creating sf::RenderTexture in other thread
Post by: eXpl0it3r on June 24, 2017, 12:36:45 am
This issue has been fixed in SFML 2.4.2. I tested it with MinGW and VS 2017 and it works fine.

If you've update from 2.4.x to 2.4.2 make sure to replace the DLLs as well.
Title: Re: Stack overflow while creating sf::RenderTexture in other thread
Post by: JAKUBW on June 24, 2017, 10:24:42 pm
Oh yeah, I updated files, but I didn't replace dll's...
Thank you very much :)