I have no idea why, but if a Texture has image data loaded when its destructor is called, it causes a segfault. I'm using CodeBlocks with MinGW, and my SFML build was just updated about a month ago. No segfault occurs if the image is not loaded, however.
Some code that reproduces the crash:
#include <SFML.hpp>
using namespace sf;
int main()
{
RenderWindow window(VideoMode(640, 480, 32), "Texture Crasher");
Texture tx1, tx2;
tx1.loadFromFile("image.png");
tx2.loadFromFile("image.png");
while(window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type==Event::Closed)
window.close();
}
window.clear();
window.display();
sleep(milliseconds(25));
}
return 0;
}
GDP outputs:
#0 7763E3BE ntdll!LdrWx86FormatVirtualImage() (C:\Windows\system32\ntdll.dll:??)
#1 00000000 0x00000000 in ??() (??:??)
Any idea on why this is happening or how I can fix it? Outside of a debugger, the program will rarely crash, but that doesn't mean everything is working ok.
I copy / pasted your code.
Using C::B and MinGW as well, SFML 2.0 rc (latest update ~3 weeks ago). Ran it through the debugger, nothing. Created a small png file "image.png". No problems anywhere. Maybe you have some other code from a global class where the ctor is called before main? And the dtor of this class causes the segfault? I don't know otherwise :-X
#include <SFML/Graphics.hpp>
using namespace sf;
int main()
{
RenderWindow window(VideoMode(640, 480, 32), "Texture Crasher");
Texture tx1, tx2;
tx1.loadFromFile("image.png");
tx2.loadFromFile("image.png");
while(window.isOpen())
{
Event event;
while (window.pollEvent(event))
{
if (event.type==Event::Closed)
window.close();
}
window.clear();
window.display();
sleep(milliseconds(25));
}
return 0;
}