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

Author Topic: Making sf::Music or sf::Sound object not working (finishes process)  (Read 2585 times)

0 Members and 1 Guest are viewing this topic.

BjornVB

  • Newbie
  • *
  • Posts: 5
    • View Profile
I'm getting into building an application using the C++ SFML library. (I'm on Windows using CLion and CMake)

Currently, my code is looking like this:

#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML Audio Test");

    sf::Music music{};
    if (!music.openFromFile("res/test.mp3")) {
        std::cout << "Failed to load music" << std::endl;
        return 1;
    }

    if (music.getStatus() != sf::Music::Status::Playing) {
        std::cout << "Music is not playing" << std::endl;
        return 1;
    }

    music.play();

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
        }
    }

    return 0;
}

However, when I try to run this program, the window never opens, sound/music never plays, and I get this in my console.

D:\PATH\NAME.exe
Process finished with exit code -1073741515 (0xC0000135)

When I remove the code related to music (sf::Music music{}; --> music.play();), the window does open and the program runs correctly.

Here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.26)
project(adaptive_audio)

set(CMAKE_CXX_STANDARD 17)

add_executable(adaptive_audio main.cpp)

set(SFML_STATIC_LIBRARIES TRUE)
set(SFML_DIR "./libraries/SFML/lib/cmake/SFML")

find_package(SFML COMPONENTS system audio network graphics window REQUIRED)

include_directories("./libraries/SFML/include/SFML")
target_link_libraries(adaptive_audio sfml-system sfml-audio sfml-network sfml-graphics sfml-window)

What am I doing wrong?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: Making sf::Music or sf::Sound object not working (finishes process)
« Reply #1 on: September 20, 2023, 03:40:09 pm »
0xC0000135 means it failed to find a required DLL.

Unfortunately CLion hides the "normal" MsgBox. If you run it from explorer, you'll get a MsgBox telling you which DLL is missing.
Since it's related to audio, you're most likely missing openal32.dll next to your executable.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BjornVB

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Making sf::Music or sf::Sound object not working (finishes process)
« Reply #2 on: September 20, 2023, 03:42:05 pm »
So having the DLLs in the library folder itself is not enough? Do I just make a copy of any missing DLLs from the SFML library?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Making sf::Music or sf::Sound object not working (finishes process)
« Reply #3 on: September 21, 2023, 09:32:26 pm »
If you're dynamically linking SFML, you'll likely need to provide the DLLs along with your executable (unless the running system has their location added to its global path). If you're statically linking SFML, you won't need to provide DLLs as these are only for dynamically linking.

EXCEPT...

...for openal32.dll

Even if you statically link and use the audio library, you'll need this DLL along with the executable as its required by its (OpenAL's) license to have it separate.
« Last Edit: September 22, 2023, 09:06:57 pm by Hapax »
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

BjornVB

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: Making sf::Music or sf::Sound object not working (finishes process)
« Reply #4 on: September 22, 2023, 10:25:15 am »
Yep, that works, thanks for the help!