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

Author Topic: SFML won't load audio files on Windows but works fine on Linux  (Read 4003 times)

0 Members and 1 Guest are viewing this topic.

MR

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Hello,

I am currently developping a project of a 3D video game in C++. I want to use the SFML Audio module to manage musics and sounds in my game. I use CMake to compile under both Linux and Windows.

Under Linux (compiles with c++ through generated Makefile), everything works perfectly fine, but when I try to launch under Windows (compiles with MSVC in a generated VS 16 (2019) solution), the SFML won't load the music anymore (more specifically, the loadFromFile function fails).

Here is the test code sample I use (directly in the main, which is just a big code sample for testing all my libraries so I just give here he SFML Audio related part):
    sf::SoundBuffer soundBuffer;          //Tried with a sf::SoundBuffer + sf::Sound
    sf::Sound sound;
    if (!soundBuffer.loadFromFile("assets/music/test_music.ogg")) //      <-- fails here
        return -2;
    sound.setBuffer(soundBuffer);
    sound.play();

    /*                          Also tried with sf::Music, with this piece of code, fails exactly at the same function call
    sf::Music music;
    if (!music.openFromFile("assets/music/test_music.ogg")) //          <-- fails here
        return -3;
    music.play();*/

 

This code runs fine under Linux, but for some reason not under Windows.
Here is what I already checked:
    - The path is right (some other assets are accessed by other libs, so I know the assets directory is accessible, and I quintuple checked the rest of the path)
    - The OGG Vorbis file is not corrupted (plays well in any media player both on Linux and Windows + recorded and encoded it myself in Audacity.
    - The SFML dependencies are correctly loaded (.dll is in the build directory, .lib is linked in CMake, headers are included correctly.)
    - I tried using the sfml-audio-d-2.dll instead of the smfl-audio-2.dll, just in case. Doesn't work either.
    - The argument format (I checked there wasn't a problem of `WCHAR *` instead of `char *`)

I use the 64 bits library, because VS wouldn't accept the 32 bits one (saying I am compiling the project for 64 bits platforms -- which is intended). I switched without really thinking about it since the game is not meant to be played on 32 bits devices, could this cause problems?

Also, I am new to programming in C++ in Windows, so there might be something I did wrong in that aspect.

Thank you in advance for any help !

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: SFML won't load audio files on Windows but works fine on Linux
« Reply #1 on: June 08, 2020, 01:30:18 pm »
If the loadFromFile function doesn't return true, then SFML will output something to sf::err() which by default is redirected to std::cerr, so what does the console say why it failed?

What's your working directory and where have you placed the assets?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MR

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML won't load audio files on Windows but works fine on Linux
« Reply #2 on: June 08, 2020, 03:38:18 pm »
Actually, until now I could not see the error messages because of another library that had a pragma setting redirecting the output to something other than the console... :/

Anyway now it's corrected, the message from the SFML is the following:
Failed to open sound file "

If my source directory is "." (CMAKE_SOURCE_DIR), then:
 - My build directory is
"./build"
(CMAKE_BINARY_DIR) (all my DLLs are copied there too)
 - My assets are originally at the source directory, so
"./assets"
- The whole assets directory is copied to the binary so it is:
"./build/assets"
- VS 2019 compiles in the Debug subdirectory in the build directory:
"./build/Debug"

My program is able to load other assets with other libs (graphical assets, with the lib Irrlicht), so I don't think the problem lies in a wrong path to the assets directory.
From the error message given by the SFML, I suspect an error in either the way I write the path in the program (although it seems fine to me) or similar.

MR

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML won't load audio files on Windows but works fine on Linux
« Reply #3 on: June 08, 2020, 03:47:04 pm »
Oh and also, in the VS properties I have this
(See attached image)

Project_dir corresponds to "./build"
« Last Edit: June 08, 2020, 03:49:03 pm by MR »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: SFML won't load audio files on Windows but works fine on Linux
« Reply #4 on: June 08, 2020, 05:36:58 pm »
Since you're building in debug mode, did you also link the SFML debug libraries (-d suffix)?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MR

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: SFML won't load audio files on Windows but works fine on Linux
« Reply #5 on: June 08, 2020, 10:18:35 pm »
Since you're building in debug mode, did you also link the SFML debug libraries (-d suffix)?

Actually no, thank you that was the problem !