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

Author Topic: [sf::Context] recursive loop, causing crash (loading resources in thread)  (Read 1936 times)

0 Members and 1 Guest are viewing this topic.

dejavu

  • Newbie
  • *
  • Posts: 4
    • View Profile
Callstack:
(...)
        appSnakeClient-vc11.exe!sf::GlResource::GlResource() Line 61    C++
        appSnakeClient-vc11.exe!sf::Context::Context() Line 61  C++
        appSnakeClient-vc11.exe!`anonymous namespace'::getInternalContext() Line 155    C++
        appSnakeClient-vc11.exe!sf::priv::GlContext::ensureContext() Line 213   C++
        appSnakeClient-vc11.exe!sf::GlResource::GlResource() Line 61    C++
        appSnakeClient-vc11.exe!sf::Context::Context() Line 61  C++
        appSnakeClient-vc11.exe!`anonymous namespace'::getInternalContext() Line 155    C++
        appSnakeClient-vc11.exe!sf::priv::GlContext::ensureContext() Line 213   C++
        appSnakeClient-vc11.exe!sf::GlResource::GlResource() Line 61    C++
        appSnakeClient-vc11.exe!sf::Context::Context() Line 61  C++
        appSnakeClient-vc11.exe!`anonymous namespace'::getInternalContext() Line 155    C++
        appSnakeClient-vc11.exe!sf::priv::GlContext::ensureContext() Line 213   C++
        appSnakeClient-vc11.exe!sf::GlResource::GlResource() Line 61    C++
        appSnakeClient-vc11.exe!sf::Context::Context() Line 61  C++
        appSnakeClient-vc11.exe!`anonymous namespace'::getInternalContext() Line 155    C++
        appSnakeClient-vc11.exe!sf::priv::GlContext::ensureContext() Line 213   C++
        appSnakeClient-vc11.exe!sf::GlResource::GlResource() Line 61    C++
        appSnakeClient-vc11.exe!sf::Context::Context() Line 61  C++
        appSnakeClient-vc11.exe!`anonymous namespace'::getInternalContext() Line 155    C++
        appSnakeClient-vc11.exe!sf::priv::GlContext::ensureContext() Line 213   C++
        appSnakeClient-vc11.exe!sf::GlResource::GlResource() Line 61    C++
        appSnakeClient-vc11.exe!sf::Context::Context() Line 61  C++
        appSnakeClient-vc11.exe!`anonymous namespace'::getInternalContext() Line 155    C++
        appSnakeClient-vc11.exe!sf::priv::GlContext::ensureContext() Line 213   C++
        appSnakeClient-vc11.exe!sf::GlResource::GlResource() Line 61    C++
 

Some parts of SFML code:
Context::Context() // <== GOES HERE! constructor is calling inherited constructor GlResource::GlResource
{
    m_context = priv::GlContext::create();
    setActive(true);
}

GlResource::GlResource()
{
    {
        // Protect from concurrent access
        Lock lock(mutex);

        // If this is the very first resource, trigger the global context initialization
        if (count == 0)
            priv::GlContext::globalInit();

        // Increment the resources counter
        count++;
    }

    // Now make sure that there is an active OpenGL context in the current thread
    priv::GlContext::ensureContext();  // <== GOES HERE!
}

void GlContext::ensureContext()
{
    // If there's no active context on the current thread, activate an internal one
    if (!currentContext)
        getInternalContext()->setActive(true); // <== GOES HERE!
}


namespace
{
    sf::Context* getInternalContext()
    {
        if (!hasInternalContext())
        {
            internalContext = new sf::Context; // <== GOES HERE!
            sf::Lock lock(internalContextsMutex);
            internalContexts.insert(internalContext);
        }

        return internalContext;
    }
}

 

dejavu

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: [sf::Context] recursive loop, causing crash (loading resources in thread)
« Reply #1 on: February 21, 2016, 12:00:42 pm »
I've fixed this issue. Check if it's correct and add it to master branch please.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
[sf::Context] recursive loop, causing crash (loading resources in thread)
« Reply #2 on: February 21, 2016, 01:33:12 pm »
It would be interesting to get a minimal and complete example first.
Just because you think you know what's broken, doesn't mean it really is, might also be your code. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

AlejandroCoria

  • Jr. Member
  • **
  • Posts: 68
    • View Profile
    • alejandrocoria.games
    • Email
Re: [sf::Context] recursive loop, causing crash (loading resources in thread)
« Reply #3 on: February 21, 2016, 03:58:37 pm »
I had the same problem, create a context in the main thread and the other in another thread causes the recursive loop (no matter in what order were created).

I solved using the branch https://github.com/SFML/SFML/tree/feature/no_internal_context.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: [sf::Context] recursive loop, causing crash (loading resources in thread)
« Reply #4 on: February 21, 2016, 05:26:38 pm »
This has been known for a while: #989

Just use https://github.com/SFML/SFML/tree/feature/no_internal_context for now.

The "fix" (and improvement) was submitted quite a while ago, however it has been stuck in "testing hell" since then. The more support the pull request gets, the faster it will eventually get merged. So feel free to leave feedback in #1002 and #989.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

 

anything