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

Author Topic: "sf::String" couldn't take "std::wstring" directly on Visual Studio 2015  (Read 8174 times)

0 Members and 1 Guest are viewing this topic.

ToyAuthor

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
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()));

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Have you tried it outside of the window constructor?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ToyAuthor

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
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.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
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);
}
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
"sf::String" couldn't take "std::wstring" directly on Visual Studio 2015
« Reply #4 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

ToyAuthor

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
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.
« Last Edit: April 01, 2017, 03:48:34 pm by ToyAuthor »

ToyAuthor

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
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() );

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
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?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ToyAuthor

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
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.
« Last Edit: April 01, 2017, 04:26:50 pm by ToyAuthor »

 

anything