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

Author Topic: Access violation with sf/std string  (Read 1657 times)

0 Members and 1 Guest are viewing this topic.

Sortoc

  • Newbie
  • *
  • Posts: 2
    • View Profile
Access violation with sf/std string
« on: April 24, 2012, 07:49:32 pm »
EDIT: Solved it, I was linking the false DLL files...

Hi i just started SFML yesterday. I wanted to start with the example code for displaying text but if i try to convert a unicode string to a single-byte string and clean up later i get a access violation at _lock. First someone told me it could be the default-font bug it happens only if i use the sf and std string.

Compiler: MSVC 2010
OS: Win-7 32 Bit

Source:
#include <Windows.h>
#include <string>
#include <SFML\Graphics.hpp>

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow )
{
        //sf::String sfStr("My Application");
        //std::string Str = sfStr.toAnsiString();

        sf::RenderWindow window(sf::VideoMode(600,400), "");
        //window.setTitle(Str);
       
        sf::Text text("First Time Test Text");

        while(window.isOpen())
        {
                sf::Event event;
                while(window.pollEvent(event))
                {
                        if(event.type == sf::Event::Closed)
                                window.close();
                }
                window.clear();
                window.draw(text);
                window.display();
        }
        return 0;
}

If I uncomment the 3 lines i get a access violation reading at 0x696c7064.

Callstack:
msvcr100d.dll!_lock(int locknum) Line 348
msvcr100d.dll!operator delete(void * pUserData) Line 45 + 0x7 Bytes
WinGame.exe!std::allocator<char>::deallocate(char * _Ptr, unsigned int __formal)  Line 182 + 0x9 Bytes   
WinGame.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Tidy(bool _Built, unsigned int _Newsize)  Line 1998
WinGame.exe!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >()  Line 755
WinGame.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int CmdShow)  Line 60 + 0x3c Bytes
WinGame.exe!__tmainCRTStartup()  Line 547 + 0x2c Bytes
WinGame.exe!WinMainCRTStartup()  Line 371


« Last Edit: April 25, 2012, 02:21:26 pm by Sortoc »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: Access violation with sf/std string
« Reply #1 on: April 25, 2012, 12:59:26 am »
You should put that edit note at the top so one does not actually have to read the whole thing.

Also the forum uses an advanced text editor so why don't you use it?
There are tags that start with a [ and end with a ]. Your code could be packed in a 'code' block and since you're using C++ you can specify that with 'code=cpp'. (Replace the ' with the brackets)

For your problem, yes you can't mix release and debug versions of SFML and that's most only because of some 'strang' string behaviour, which I can't remember anymore. Just don't mix them and everything will be fine.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Sortoc

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Access violation with sf/std string
« Reply #2 on: April 25, 2012, 02:20:49 pm »
Thanks for your hint I didn´t see a button for code tags so i thought they are not available.