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

Author Topic: loadFromFile UNICODE path not working  (Read 3337 times)

0 Members and 1 Guest are viewing this topic.

Wafthrudnir

  • Newbie
  • *
  • Posts: 26
    • View Profile
loadFromFile UNICODE path not working
« on: June 17, 2017, 05:27:34 pm »
I am trying to load a file from this path:

C:\Testи\\pic.jpg

using this code (not using code tag, since it destroy the Cyrillic char):

   std::string file = u8"C:\\Testи\\UnicodePathCheck\\pic.jpg"; //does not work

   sf::Texture tex;
   tex.loadFromFile(file) //returns false



It works fine without the Cyrillic character in the path.

Since SFML does not provide a std::wstring overload, I guess it's impossible to load files from paths with characters outside the ASCII range?!

I checked the sources and figured that underlying stb_image library also would need an update to make this work. std::ifstream refuses to load the file. using std::wifstream with std::wstring works

My questions:
« Last Edit: June 17, 2017, 05:29:26 pm by Wafthrudnir »
Black Metal + Coding = Win!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: loadFromFile UNICODE path not working
« Reply #1 on: June 17, 2017, 05:41:24 pm »
1. No, your conclusion is perfectly right.

2. Yes of course.

3. It is an issue that will be fixed, but it's always better to use ASCII paths to avoid troubles anyway ;)
Laurent Gomila - SFML developer

Wafthrudnir

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: loadFromFile UNICODE path not working
« Reply #2 on: June 17, 2017, 06:10:07 pm »
Thanks for your reply Laurent!

Good to hear it will be supported sometime in the future (is there any current roadmap, couldn't find one)

3. It is an issue that will be fixed, but it's always better to use ASCII paths to avoid troubles anyway ;)

Yes, correct. The thing is, I don't know in which path the user will copy my game. Let's say I sell a game via Steam and Steam is installed in "C:\游戏\steamapps\", the game won't run.

I guess nowadays file operations must be done with Unicode if you plan to distribute your software worldwide  :-\
Black Metal + Coding = Win!

ToyAuthor

  • Newbie
  • *
  • Posts: 21
    • View Profile
    • Email
Re: loadFromFile UNICODE path not working
« Reply #3 on: June 22, 2017, 03:18:55 am »
This issue is nothing.
You can use _wfopen to get your file, then passing it from memory to SFML.
The stb_image library also provide a function named "stbi_load_from_callbacks" to do it.
« Last Edit: June 22, 2017, 06:42:45 am by ToyAuthor »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: loadFromFile UNICODE path not working
« Reply #4 on: June 22, 2017, 08:04:24 am »


Yes, correct. The thing is, I don't know in which path the user will copy my game. Let's say I sell a game via Steam and Steam is installed in "C:\游戏\steamapps\", the game won't run.

I guess nowadays file operations must be done with Unicode if you plan to distribute your software worldwide  :-\
So you're using the absolute path? Why not just work with relative paths?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/