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 !
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.