1
General / SFML 2.4 - getInternalContext segfault when loading texture from a thread
« on: August 12, 2016, 04:05:27 pm »
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.
The Callstack, if it can help :
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.
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;
}
#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)
#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.