I am in a process of making a game (Breakout clone).
I have solved several problems concerning
sf::text (loading font, and passing font AND text by reference), and it works just fine, but there is still one problem left: when I
close my window, it crashes with a system message "program.exe has stopped working" and "Windows is checking for a solution".
Build log shows
only one message: "Process terminated with status
-1073741819" (this is not a random number, every time it ends with the same code, no matter what stage of the game I exit from).
When I remove the line
window.draw(text), the program runs OK and ends OK.
I use Code::Blocks 13.12 with the latest version of SFML, everything is perfectly configured (I have done A LOT of reading on that subject), it seems like some bug on this function?
My code is too big and complex to post it here (10 files, 4 classes), but if it is needed to see what is going on, I'll take the effort to copy/paste it.
When I run the program in DEBUG mode, i get 12 lines:
#0 77B4DFD4 ntdll!TpWaitForWork() (C:\Windows\system32\ntdll.dll:??)
#1 41A00000 ?? () (??:??)
#2 0028F83C ?? () (??:??)
#3 775998CD msvcrt!free() (C:\Windows\syswow64\msvcrt.dll:??)
#4 00AD0000 ?? () (??:??)
#5 004E0FD0 __gnu_cxx::new_allocator<sf::Vertex>::deallocate(this=0x28fb10, __p=0x41a00000) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/ext/new_allocator.h:100)
#6 00517572 std::_Vector_base<sf::Vertex, std::allocator<sf::Vertex> >::_M_deallocate(this=0x28fb10, __p=0x41a00000, __n=2575617234) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_vector.h:175)
#7 0051772E std::_Vector_base<sf::Vertex, std::allocator<sf::Vertex> >::~_Vector_base(this=0x28fb10, __in_chrg=<optimized out>) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_vector.h:161)
#8 0053752C std::vector<sf::Vertex, std::allocator<sf::Vertex> >::~vector(this=0x28fb10, __in_chrg=<optimized out>) (c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/include/c++/bits/stl_vector.h:404)
#9 004DE0DF sf::VertexArray::~VertexArray(this=0x28fb0c, __in_chrg=<optimized out>) (D:/Diplomski/CodeBlocks/SFML-2.3.2/include/SFML/Graphics/VertexArray.hpp:45)
#10 004DF6C2 sf::Text::~Text(this=0x28fa30, __in_chrg=<optimized out>) (D:/Diplomski/CodeBlocks/SFML-2.3.2/include/SFML/Graphics/Text.hpp:48)
#11 004E0812 Rezultat::~Rezultat(this=0x28f924, __in_chrg=<optimized out>) (include/Rezultat.h:6)
#12 00401D9A main() (D:\Diplomski\CodeBlocks\Diplomski\main.cpp:152)
I have found THIS thread with the same error:
http://en.sfml-dev.org/forums/index.php?topic=6130.0BUT, I am not using default font, I load "verdana.ttf" and it works fine!
To prevent the crash, the default font must never be instanciated, so you have to pass your own font to the constructor of all your sf::Text instances.
Doing it with the SetFont function is already too late.
Good hint is to send the font to the constructor, so I am going to try this.
EDIT: I am not able to use the constructor with the font, I will post my code to show why.