-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on shutdown when rendering sf::Text with default font #59
Comments
If you add a call to Display for the window does it work then? Just wondering. Still not good behavior. |
It's a known bug, I thought there was already a task for this. Anyway, the forum is full of messages about it. |
Not sure if this will help but it only crashes if you close via a window. If you have a console and close through that there is no problem. |
Closing through the console is akin to simply calling exit(randomnumber) thereby avoiding all sfml cleanup functions so you don't get any errors. |
After reading this and (more important) this thread I tried something new. #include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
int main()
{
sf::RenderWindow win(sf::VideoMode(800, 600), "Test");
sf::Text txt("Test");
win.Draw(txt); // Without drawing, no crash occurs, as before
} Crash (same as above): #include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Font.hpp>
int main()
{
sf::RenderWindow win(sf::VideoMode(800, 600), "Test");
sf::Text txt("Test", sf::Font::GetDefaultFont()); // Note the explicit GetDefaultFont() here.
win.Draw(txt);
} No crash: #include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Font.hpp>
int main()
{
sf::RenderWindow win(sf::VideoMode(800, 600), "Test");
sf::Font fnt(sf::Font::GetDefaultFont()); // <--------------------------
sf::Text txt("Test", fnt); // If I don't pass fnt to constructor and don't set it via SetFont() it also crashes.
win.Draw(txt);
} If I move the line which defines the font before the RenderWindow, no crash occurs either. This is clearly related to construction/destruction order (destruction order is the reversed construction order). EDIT: Fixed markdown EDIT2: When I explicitly call sf::Font::GetDefaultFont() before the construction of the text (in the original crashing program), I have a different callstack, when it crashes: int main()
{
sf::Font::GetDefaultFont();
sf::RenderWindow win(sf::VideoMode(800, 600), "Test");
sf::Text txt("Test");
win.Draw(txt); // Without drawing, no crash occurs
} leads to atioglxx.dll!698bd4cf() [Frames below may be incorrect and/or missing, no symbols loaded for atioglxx.dll] atioglxx.dll!698c9079() atioglxx.dll!6937baac() msvcr100d.dll!___freeCrtMemory() + 0x317 bytes msvcr100d.dll!_exit() + 0x12 bytes fontcrash.exe!__tmainCRTStartup() Line 568 C fontcrash.exe!WinMainCRTStartup() Line 371 C kernel32.dll!@BaseThreadInitThunk@12() + 0x12 bytes ntdll.dll!___RtlUserThreadStart@8() + 0x27 bytes ntdll.dll!__RtlUserThreadStart@8() + 0x1b bytes |
Maybe the problem could be solved by letting the user manage the lifetime of the default font and providing a method |
I'm also getting a crash with SFML.Net on exit in atioglxx.dll. Unfortunately it's not giving me a call stack so I can't provide it. I assume it is caused by this same issue. I believe the user needs a way to manage the lifetime of the default font as Oberon is suggesting. Doing otherwise seems to be too problematic. Edit: So far the order of operations doesn't seem to affect whether or not it crashes. Even if I do Font.DefaultFont.Dispose() it still crashes. (I don't know whether this is even doing what I want) Should I open a separate issue for this in the SFML.net repo? Edit 2: Okay I've narrowed down the issue, going to open a ticket on the other repo. |
You don't need to, it's most likely the same issue. |
Too late, already made it: SFML/SFML.Net#11 The issue seems to involve the constructor for the Text class, so its not quite the same. Edit: I reviewed the cases and figured that it happens whenver you set a Text string before setting the font, which is what happens in the constructor in certain cases. So it seems I just have to make sure a non-default font is specified before I set the display string and no crash will happen. |
Solved by removing the default font in commit a0c1f5f |
I have Windows 7 x64, Ati Radeon 5650 (Mobile) and Visual Studio 2010. SFML revision (or last commit) is d497401 (the latest at the time I am writing this).
Consider the following code:
Any program will crash when the SFML default font is used and the text is drawn to the window.
The crash happens at exit, in GlResource.cpp, Line 80 at the end of the Destructor of GlResource.
Error is: exception at 0x690974c4 in sf-crash.exe: 0xC0000005: Access violation reading location 0x00000008. It seems to be an a problem with a null pointer (location is 0 + offset of a member(?)).
Callstack was:
The text was updated successfully, but these errors were encountered: