Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Runtime error sf::String  (Read 4875 times)

0 Members and 2 Guests are viewing this topic.

Damacustas

  • Newbie
  • *
  • Posts: 3
    • View Profile
Runtime error sf::String
« on: February 23, 2013, 08:53:02 pm »
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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Runtime error sf::String
« Reply #1 on: February 23, 2013, 09:54:59 pm »
You must recompile SFML, there's no precompiled version for Visual C++ 11.
Laurent Gomila - SFML developer

Damacustas

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Runtime error sf::String
« Reply #2 on: February 23, 2013, 10:28:40 pm »
Thanks, that fixed the problem. I hadn't thought of recompiling since this isn't the first time I use libraries compiled by an older compiler, previously I encountered no issues.

Thanks again. :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Runtime error sf::String
« Reply #3 on: February 23, 2013, 10:33:31 pm »
Quote
Thanks, that fixed the problem. I hadn't thought of recompiling since this isn't the first time I use libraries compiled by an older compiler, previously I encountered no issues.
Must be C libraries, because when C++ is involved, there's no compatibility between versions of VC++.
Laurent Gomila - SFML developer

Damacustas

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Runtime error sf::String
« Reply #4 on: February 24, 2013, 01:46:14 am »
nope, I'm sure I used the C++ libraries.
I used SFML 1.6 libraries pre-compiled by vs2008 with vs2010 and even recently I used those same libraries with vs2012. Only a week ago I decided to use SFML 2.0 and didn't have any issues except for the issue that started the thread.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11008
    • View Profile
    • development blog
    • Email
AW: Runtime error sf::String
« Reply #5 on: February 24, 2013, 07:42:53 am »
Yeah it "works" until it crashes. ;)
It's not like there's a if(version==2010) app.crash(), but they are not fully compatible after all.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Runtime error sf::String
« Reply #6 on: February 24, 2013, 10:28:59 am »
Wouldn't it be possible to write two almost identical functions that appear only in debug, one inline so it uses the real macro and one not inline so the macro is expanded in it and stored inside system lib and then compare their output to catch errors like that easily? And by macro I mean any macro that identifies the compiler. It could clash across compilers but if someone links GCC compiled SFML to VS __AND__ the VS manages to link and run that without screaming like Ballmer* then.. well.. sucks to be him.

*Reference video of what C and c++ does in case of such esoteric errors:

Actually, on second thought, that might be too much foolproofing.
« Last Edit: February 24, 2013, 10:37:39 am by FRex »
Back to C++ gamedev with SFML in May 2023

 

anything