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

Author Topic: SFML 2.4 - getInternalContext segfault when loading texture from a thread  (Read 1921 times)

0 Members and 1 Guest are viewing this topic.

Fabien

  • Newbie
  • *
  • Posts: 1
    • View Profile
Hi  :)

I decided to try SFML 2.4 on some of my projects yesterday and I have an issue with one of them.
I managed to isolate the problem : when I load a texture in a thread, it triggers a Segfault in GlContext.cpp, line 159.
I can't figure how to fix it or if I'm doing something wrong.

Minimal code :
Note: it works fine with SFML 2.3.2.
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

sf::Texture* texture;
sf::Sprite* sprite;
sf::Mutex* mutex;

void load()
{
    mutex->lock();
    if(texture->loadFromFile("ok.png")) sprite->setTexture(*texture);
    mutex->unlock();
}

int main()
{
    sf::RenderWindow window(sf::VideoMode(100, 100), "SFML test");

    texture = new sf::Texture();
    sprite = new sf::Sprite();
    mutex = new sf::Mutex();

    sf::Thread thread(&load);
    thread.launch();

    while(window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        mutex->lock();
        window.draw(*sprite);
        mutex->unlock();
        window.display();

    }
    thread.wait();

    delete texture;
    delete sprite;
    delete mutex;
    return 0;
}

The Callstack, if it can help :
#0 0x7752df87   ntdll!memcpy() (C:\Windows\SysWOW64\ntdll.dll:??)
#1 0x77533431   ntdll!RtlQueryPerformanceCounter() (C:\Windows\SysWOW64\ntdll.dll:??)
#2 0x775d0f0e   ntdll!RtlpNtEnumerateSubKey() (C:\Windows\SysWOW64\ntdll.dll:??)
#3 0x7758aa86   ntdll!RtlUlonglongByteSwap() (C:\Windows\SysWOW64\ntdll.dll:??)
#4 0x830000     ?? () (??:??)
#5 0x77533431   ntdll!RtlQueryPerformanceCounter() (C:\Windows\SysWOW64\ntdll.dll:??)
#6 0x76009d45   msvcrt!malloc() (C:\Windows\syswow64\msvcrt.dll:??)
#7 0x50974a     operator new(unsigned int) () (??:??)
#8 0x41ea4f     (anonymous namespace)::getInternalContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:159)
#9 0x41ed1e     sf::priv::GlContext::ensureContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:217)
#10 0x41fb90    sf::GlResource::GlResource(this=0x62301a8) (D:\SFML-2.4.0-sources\src\SFML\Window\GlResource.cpp:60)
#11 0x41e4a0    sf::Context::Context(this=0x62301a8) (D:\SFML-2.4.0-sources\src\SFML\Window\Context.cpp:60)
#12 0x41ea58    (anonymous namespace)::getInternalContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:159)
#13 0x41ed1e    sf::priv::GlContext::ensureContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:217)
#14 0x41fb90    sf::GlResource::GlResource(this=0x6230188) (D:\SFML-2.4.0-sources\src\SFML\Window\GlResource.cpp:60)
#15 0x41e4a0    sf::Context::Context(this=0x6230188) (D:\SFML-2.4.0-sources\src\SFML\Window\Context.cpp:60)
#16 0x41ea58    (anonymous namespace)::getInternalContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:159)
#17 0x41ed1e    sf::priv::GlContext::ensureContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:217)
#18 0x41fb90    sf::GlResource::GlResource(this=0x6230168) (D:\SFML-2.4.0-sources\src\SFML\Window\GlResource.cpp:60)
#19 0x41e4a0    sf::Context::Context(this=0x6230168) (D:\SFML-2.4.0-sources\src\SFML\Window\Context.cpp:60)
#20 0x41ea58    (anonymous namespace)::getInternalContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:159)
#21 0x41ed1e    sf::priv::GlContext::ensureContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:217)
#22 0x41fb90    sf::GlResource::GlResource(this=0x6230148) (D:\SFML-2.4.0-sources\src\SFML\Window\GlResource.cpp:60)
#23 0x41e4a0    sf::Context::Context(this=0x6230148) (D:\SFML-2.4.0-sources\src\SFML\Window\Context.cpp:60)
#24 0x41ea58    (anonymous namespace)::getInternalContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:159)
#25 0x41ed1e    sf::priv::GlContext::ensureContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:217)
#26 0x41fb90    sf::GlResource::GlResource(this=0x6230128) (D:\SFML-2.4.0-sources\src\SFML\Window\GlResource.cpp:60)
#27 0x41e4a0    sf::Context::Context(this=0x6230128) (D:\SFML-2.4.0-sources\src\SFML\Window\Context.cpp:60)
#28 0x41ea58    (anonymous namespace)::getInternalContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:159)
#29 0x41ed1e    sf::priv::GlContext::ensureContext() (D:\SFML-2.4.0-sources\src\SFML\Window\GlContext.cpp:217)
 

I'm on windows 7 64 bits (but I do compile in 32 bits), NVidia Graphic card.
I use Code::Blocks and both version of SFML are compiled from the sources with the same compiler.

eigen

  • Jr. Member
  • **
  • Posts: 64
  • Brobdingnagian ding dong
    • View Profile
    • Pioneersgame.com
Same problem here. Previously was using 2.3.2 and I noticed the problem when building the latest source myself but thought the problem was compiler mis-match or something. It only seems to affect creating new textures, sounds seem to load fine although about 3-4 times slower which is weird too.

Have to revert back to 2.3.2 for now.
« Last Edit: August 13, 2016, 11:28:54 am by eigen »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
See the discussion and linked PR: https://github.com/SFML/SFML/issues/989
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything