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

Author Topic: toAnsiString causes crash  (Read 6351 times)

0 Members and 1 Guest are viewing this topic.

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
toAnsiString causes crash
« on: February 21, 2015, 06:47:29 am »
first, I'm using visual studio express 2012, with the sfml2.2.

I've trying to convert from sf::String to std::string. Basically I want user to input numbers, convert those numbers to int and then perform various calculations based on the input.

However every-time I run toAnsiString(), I get an error during the operator delete. The error is:-



When I press retry and I look into the stack, I see that the first entry in the stack is below.



Then the next stack entry up is below:



And then I see the operator delete in the next one.



My code is extremely basic as I've scaled it right back now to try to determine what I am doing wrong. I'm still very new to programming so help appreciated....with basic instructions. :) I have double checked to ensure that sfml lib are linked correctly, i.e. I ensure I didn't mix up -d libs in the release configuration and vice-versa.

Here is my code. first my header

#ifndef TEST_H
#define TEST_H

#include <string>
#include <SFML/Graphics.hpp>

using namespace std;

class testClass
{
public:

        testClass();

        void testSFString();
        bool chkStr();

private:
        sf::String SFStr;
        std::string stdStr;
};

#endif

 

Then my source file.
#include "test.h"

testClass::testClass()
{

}

void testClass::testSFString()
{
        SFStr = "testStr";
        if (chkStr())
        {
                stdStr = SFStr.toAnsiString(); //dies here
        }
}

bool testClass::chkStr()
{
        if (!SFStr.isEmpty())
                return true;
        else
                return false;
}
 

finally my main

#include "test.h"

int main()
{
        testClass test;

        test.testSFString();
}
 

Gan

  • Jr. Member
  • **
  • Posts: 98
    • View Profile
Re: toAnsiString causes crash
« Reply #1 on: February 21, 2015, 07:46:28 am »
I'm not sure if this is helpful but in the documentation, this part jumped out at me:

Quote
It automatically handles conversions from/to ANSI and wide strings, so that you can work with standard string classes and still be compatible with functions taking a sf::String.

sf::String s;
std::string s1 = s;  // automatically converted to ANSI string

You shouldn't need to call the ansi function.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: toAnsiString causes crash
« Reply #2 on: February 21, 2015, 10:39:01 am »
Make sure that you don't use release libraries in debug mode. And that you're using the VS 2012 SFML libraries for x86.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
AW: toAnsiString causes crash
« Reply #3 on: February 21, 2015, 10:39:06 am »
Sounds like you get a heap corruption for whatever reason.

Can you provide the full call stack so we see where the crash originated from?

As side notes: Don't use "using namespace std", the chkStr can just be written as return SFStr.isEmpty().
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: toAnsiString causes crash
« Reply #4 on: February 21, 2015, 11:34:55 pm »
I'm not sure if this is helpful but in the documentation, this part jumped out at me:

Quote
It automatically handles conversions from/to ANSI and wide strings, so that you can work with standard string classes and still be compatible with functions taking a sf::String.

sf::String s;
std::string s1 = s;  // automatically converted to ANSI string

You shouldn't need to call the ansi function.

Hi,

I've tried the below but I get the same error message.

stdStr = SFStr;
 

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: toAnsiString causes crash
« Reply #5 on: February 21, 2015, 11:40:18 pm »
Make sure that you don't use release libraries in debug mode. And that you're using the VS 2012 SFML libraries for x86.

Hi,

The sfml zip file that I downloaded is called "SFML-2.2-windows-vc12-32-bit.zip" - so this does look like the VC2012 32 bit files. I have other sfml programs that work fine, however this is the first time I've tried to convert a sf::string to the std::string.

For the other libs. I re-checked the project properties. I went to Linker -> Input.

Under Debug I have the below as additional dependencies

"tgui-d.lib;sfml-main-d.lib;sfml-graphics-d.lib;sfml-window-d.lib;sfml-system-d.lib;sfml-audio-d.lib;sfml-network-d.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)"
 

Under Release I have the below

tgui.lib;sfml-main.lib;sfml-graphics.lib;sfml-window.lib;sfml-system.lib;sfml-audio.lib;sfml-network.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
 

I don't see any mix-up? Unless you can see something?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: toAnsiString causes crash
« Reply #6 on: February 21, 2015, 11:44:09 pm »
VC 12 is the compiler of Visual Studio 2013 (it's clearly written on the download page). The compiler that matches Visual Studio 2012 is VC 11.
Laurent Gomila - SFML developer

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: toAnsiString causes crash
« Reply #7 on: February 22, 2015, 12:19:09 am »
VC 12 is the compiler of Visual Studio 2013 (it's clearly written on the download page). The compiler that matches Visual Studio 2012 is VC 11.

Ok. I downloaded file. SFML-2.2-windows-vc11-32-bit.zip

I changed the Additional Include directory and additional lib directory settings to ensure it used the the extract files from above zip. I get the same error.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: toAnsiString causes crash
« Reply #8 on: February 22, 2015, 12:22:49 am »
Did you replace the DLLs as well? Are you certain? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: AW: toAnsiString causes crash
« Reply #9 on: February 22, 2015, 12:23:10 am »
Sounds like you get a heap corruption for whatever reason.

Can you provide the full call stack so we see where the crash originated from?

As side notes: Don't use "using namespace std", the chkStr can just be written as return SFStr.isEmpty().

Ok, so I provided screen shots in the first post of the first parts of the call stack. however i failed to open the call stack window - sorry.

See below the additional files in the call stack - alongwith the call stack window. I hope this contains the information that you were looking for? sorry in advance if I've misunderstood.


















starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: toAnsiString causes crash
« Reply #10 on: February 22, 2015, 12:26:12 am »
Did you replace the DLLs as well? Are you certain? ;)

oops I obviously put up the screen-shots before seeing this post - I'll double-check and get back to you.

BTW:- thanks for the assistance. :)

starkhorn

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
    • Email
Re: toAnsiString causes crash
« Reply #11 on: February 22, 2015, 12:42:17 am »
Did you replace the DLLs as well? Are you certain? ;)

 :-[ :-[ :-[ :-[ :-[

Really sorry folks. So yes I was using the correct include and lib files, but the DLL's that I had copied into my project folder were still the incorrect DLL's for visual studio 2013.

Many thanks for the assistance.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: toAnsiString causes crash
« Reply #12 on: February 22, 2015, 12:50:04 am »
Glad you solved it and don't worry, you're not the first one who forgot to replace the DLLs. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/