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

Author Topic: sf::Texture Destructor Causing Segfault  (Read 3374 times)

0 Members and 1 Guest are viewing this topic.

22ndCG

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
sf::Texture Destructor Causing Segfault
« on: October 27, 2012, 05:50:05 am »
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.

7krs

  • Newbie
  • *
  • Posts: 39
    • View Profile
    • Email
Re: sf::Texture Destructor Causing Segfault
« Reply #1 on: October 28, 2012, 11:30:41 pm »
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;
}
 

22ndCG

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::Texture Destructor Causing Segfault
« Reply #2 on: October 29, 2012, 11:53:00 pm »
It must be my build then. That same exact example causes the segfault for me. I'll re-download and recompile SFML. Thanks.

 

anything