I have started with the tutorials and let my project grow. When I added a text it started to crash at shutdown, it does not affect the gameplay but it is annoying. Now, I have shrunk the code to a minimal example. Can you see what is wrong?
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(700, 400), "hejsan", sf::Style::Default);
sf::Font font_;
sf::Text text_;
// Just any font. (Still crashes at shutdown even if the line is removed.):
font_.loadFromFile("C:\\Windows\\fonts\\DejaVuSansMono.ttf");
text_.setFont(font_);
text_.setString("hejsan");
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
window.draw(text_);
window.display();
}
return 0;
}
Compiler (build chain):Microsoft Visual C++ 2017
Error message:
Exception thrown at 0x00303A18 in ConsoleApplication1.exe: 0xC0000005: Access violation writing location 0xCDCDCDCD
Call stack:
ConsoleApplication1.exe!std::_Container_base12::_Orphan_all() Line 256 C++ Non-user code. Symbols loaded. ConsoleApplication1.exe!std::_Vector_alloc<std::_Vec_base_types<sf::Vertex,std::allocator<sf::Vertex> > >::_Orphan_all() Line 580 C++ Non-user code. Symbols loaded.
ConsoleApplication1.exe!std::vector<sf::Vertex,std::allocator<sf::Vertex> >::_Tidy() Line 2003 C++ Non-user code. Symbols loaded.
ConsoleApplication1.exe!std::vector<sf::Vertex,std::allocator<sf::Vertex> >::~vector<sf::Vertex,std::allocator<sf::Vertex> >() Line 921 C++ Non-user code. Symbols loaded.
ConsoleApplication1.exe!sf::VertexArray::~VertexArray() C++ Non-user code. Symbols loaded.
ConsoleApplication1.exe!sf::Text::~Text() C++ Non-user code. Symbols loaded.
> ConsoleApplication1.exe!main() Line 27 C++ Symbols loaded.
[External Code] Annotated Frame