I'm having an issue when using toAnsiString() in conjunction with std::ofstream. The function runs fine until it returns, in which case it crashes.
Here's the minimal code:
#include <SFML/System.hpp>
#include <fstream>
#include <string>
int main()
{
// You could replace OUTPUT/OUTPUT.txt with your existing home directory
sf::String filepath = "OUTPUT/OUTPUT.txt";
// I suspect this is what is causing problems
std::string tempout = filepath.toAnsiString();
std::ofstream fileoutput ( tempout.c_str() );
if (fileoutput.is_open())
{
fileoutput << "Output";
}
}
The text file is created and contains "Output", but the program crashes on exit.
Here is the setup I'm using:
OS: Wndows 7 (64-bit)
Graphics device: Intgrated Intel graphics
SFML: v2.1 standard release (dynamically linked)
Compiler: Visual C/C++ 2010 (32-bit) -- compiled directly from the command prompt
I've also run the code in WinDbg. I get this when main() returns:
1 HEAP[minimal.exe]: Invalid address specified to RtlFreeHeap( 00550000, 005A3808 )
2 (d28.1070): WOW64 breakpoint - code 4000001f (first chance)
3 First chance exceptions are reported before any exception handling.
4 This exception may be expected and handled.
5 ntdll32!RtlpBreakPointHeap+0x23:
6 77950574 cc int 3Any help is appreciated.