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

Author Topic: [Resolved] Stack overflow in GlContext::ensureContext()  (Read 1604 times)

0 Members and 1 Guest are viewing this topic.

Kipernal

  • Newbie
  • *
  • Posts: 29
    • View Profile
[Resolved] Stack overflow in GlContext::ensureContext()
« on: August 21, 2016, 03:36:47 pm »
Hi all,

I'm having a problem where initializing anything that uses a GLResource causes a stack overflow when initialized on a separate thread:

#include <SFML/Graphics.hpp>

int main()
{
        sf::Window w;
        auto thread = std::thread{ []
        {
                sf::Texture t;  // Stack overflow occurs here
        }};
        thread.join();
        return 0;
}

What happens here is:
Texture::Texture() calls
GlResource::GlResource(), which calls
GlContext::ensureContext(), which calls
GlContext::getInternalContext(), which calls
Context::Context() (trying to create an internal context), which calls
GlResource::GlResource(), and now we're in an infinite loop.

I know threading is a Bad Thing™, but in order to have smooth window resizing events and drawing need to happen on separate threads, and you can only pump events from the thread that created the window.  So I need to create a window and poll its events in thread #1, and draw to it in thread #2.  Creating the window and drawing to the window both use GLResources, but I'm running into the error above.  If anyone could shed some light on this issue I'd be very grateful.
« Last Edit: August 21, 2016, 06:29:38 pm by Kipernal »

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: Stack overflow in GlContext::ensureContext()
« Reply #1 on: August 21, 2016, 05:16:53 pm »
Already tracked in #989. Try PR #1002 for now.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

Kipernal

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Stack overflow in GlContext::ensureContext()
« Reply #2 on: August 21, 2016, 06:29:24 pm »
Alright, that makes sense.  One of the comments in the source says "If there's no active context on the current thread, activate an internal one" so I just assumed SFML by default would be okay it.  Thanks for the information!

 

anything