SFML community forums

General => General discussions => Topic started by: ToyAuthor on April 01, 2017, 04:47:22 am

Title: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
Post by: ToyAuthor on April 01, 2017, 04:47:22 am
It happened at SFML v2.4.2
I am not sure it is belong to SFML or not.

// It's only crash on Visual Studio 2015
sf::Window(sf::VideoMode(800,600),sf::String(std::wstring(L"title")));

// It looks fine on any compiler
sf::Window(sf::VideoMode(800,600),sf::String(std::wstring(L"title").c_str()));
Title: Re: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
Post by: Hapax on April 01, 2017, 11:36:21 am
Have you tried it outside of the window constructor?
Title: Re: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
Post by: ToyAuthor on April 01, 2017, 02:17:02 pm
Have you tried it outside of the window constructor?
I was tried.
Nothing wrong with sf::Window constructor.
It's all about sf::String constructor.

Maybe something wrong with "std::basic_string" on Visual Studio 2015.
Title: Re: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
Post by: Hapax on April 01, 2017, 02:33:53 pm
So this doesn't work for you?:
#include <string>
#include <SFML/System/String.hpp>
int main()
{
        std::string s{ "string" };
        sf::String sfs(s);
        std::wstring w{ L"wide string" };
        sf::String sfw(w);
}
Title: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
Post by: eXpl0it3r on April 01, 2017, 03:14:41 pm
What's the crash? What's the call stack? Do you mix debug and release version?

You don't really need to convert L"" to std::wstring first.
Title: Re: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
Post by: ToyAuthor on April 01, 2017, 03:28:32 pm
So this doesn't work for you?:
#include <string>
#include <SFML/System/String.hpp>
int main()
{
        std::string s{ "string" };
        sf::String sfs(s);
        std::wstring w{ L"wide string" };
        sf::String sfw(w);
}
I just try it.
"sf::String" really couldn't take "std::wstring" on Visual Studio 2015.
Title: Re: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
Post by: ToyAuthor on April 01, 2017, 03:47:28 pm
What's the crash? What's the call stack? Do you mix debug and release version?

You don't really need to convert L"" to std::wstring first.
I set "release" to CMAKE_BUILD_TYPE.
It should always crash if I mix debug and release version.
My SFML library is download from the official website.(Not compile it by myself)

-----------Error message box give me this-----------
Debug error!
Program:
D:\...\my_project.exe
abort() has been called
(Press Retry to debug the application)
-----------------------------------------------------------

// It crash too
std::string   str("just a UTF-8 string");
return sf::String::fromUtf8( str.begin(), str.end() );
Title: Re: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
Post by: Hapax on April 01, 2017, 03:48:15 pm
Yes it does work or yes it doesn't?

Are you saying that it works if a temporary is created first as in my example but not otherwise?
How about this:
#include <string>
#include <SFML/System/String.hpp>
int main()
{
        sf::String a(std::wstring(L"wide string"));
        sf::String b(L"wide string");
}
Any problems here?
Title: Re: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
Post by: ToyAuthor on April 01, 2017, 04:16:46 pm
Thank you Hapax and eXpl0it3r.

And eXpl0it3r probably right.
Maybe CMAKE_BUILD_TYPE doesn't work on Visual Studio.
I usually run Visual Studio Solution in command line.
So I must be screw up something on it.

I will rebuild entire project then try again.

-----------------

I am mix debug and release version.
After rebuild all, it works fine.
My bad.