Hello,
I've written a class for reading textfiles. I'm currently using std::string but I wanted to switch to sf::String for better Unicode support, but as soon as I make any function use sf::String I get runtime errors.
For example, I have the following function, which executes just fine:
bool Open(const std::string& filename)
{
if(this->IsOpen())
this->Close();
this->_stream.open(filename.c_str()); // _stream is of type std::ifstream.
return this->_stream.good();
}
If I change it to this, things go wrong.
bool Open(const sf::String& filename)
{
if(this->IsOpen())
this->Close();
this->_stream.open(filename.toAnsiString().c_str());
return this->_stream.good();
}
After execution of this function, (when the temp std::string created by toAnsiString() gets destroyed) I get a "Application has triggered a breakpoint." with a callstack:
std::basic_string<char, std::char_traits<char> >::~std::basic_string<char, std::char_traits<char> >()
*std::basic_string internal calls*
std::allocator<char>::deallocate(char *_Ptr, unsigned int __formal)
operator delete (void* pUserData);
*more CRT internal calls*
_CrtIsValidHeapPointer(const void *pUserData)
Am I doing something wrong?
My setup:
- SFML 2.0 snapshot (linking against sfml-system-d.lib)
- Visual Studio Express 2012
- Windows 8 x64, compiling for x86
Thanks in advance for any help.