0

I'm running into a problem when using the SDL2 Mixer library in my C++ project. As soon as I'm calling a function on a class that #includes SDL_mixer.h, the project will not run. When trying to Run it, I get the following message:

enter image description here

When debugging the project, the process finishes with exit code 0, but with an additional message:

enter image description here

and

enter image description here

As you might be able to deduce, adding breakpoints to the code does not provide any additional information as the project doesn't start at all.

Commenting out the lines that use the class that include mixer makes the project runnable again seemingly without issues. I've tried to google the error code, but I can't find any documentation on what it means.

Other, possibly relevant information: I'm using conan to install my libraries and have it set to auto-install any dependencies.

I'll post the header code of the class in question here, though I don't believe the problem lies here as the project won't run to even reach the code anyway.

#include <SDL.h>
#include <SDL_mixer.h>
#include <memory>
#include <string>
#include <map>

class SoundService {
public:

    /*******************************************************************************
        * @brief Gets the singleton instance of the SoundService class.
         *
         * @return A reference to the instance of the SoundService.
         ******************************************************************************/
    static std::unique_ptr<SoundService> &getInstance() {
        if (instance == nullptr) {
            if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) < 0){
                SDL_Log("Mixer Initialization Error: %s", Mix_GetError());
            }
            instance = std::unique_ptr<SoundService>(new SoundService());
        }

        return instance;
    }

    /**
     * @brief Loads a music file and stores it with a given id string.
     * @param id
     * @param filePath
     * @return True if the asset has been loaded successfully, otherwise false.
     */
    bool loadMusic(const std::string &id, const std::string &filePath);

    void playMusic(const std::string &id, int loops = -1);

    void pauseMusic();

    void resumeMusic();

    /**
     * @brief Removes a music file by id.
     * @param id
     * @return True if the asset has been removed successfully, otherwise false.
     */
    bool removeMusic(std::string &id);

    /**
     * @brief Loads an sfx file and stores it with a given id string.
     * @param id
     * @param filePath
     * @return True if the asset has been loaded successfully, otherwise false.
     */
    bool loadSFX(const std::string &id, const std::string &filePath);

    void playSFX(const std::string &id, int loops = 0, int channel = 0);

    /**
     * @brief Removes an sfx file by id.
     * @param id
     * @return True if the asset has been removed successfully, otherwise false.
     */
    bool removeSFX(std::string &id);

    /**
     * @brief Removes all the music files and sfx files from the sound service
     */
    void clear();

private:
    SoundService() = default;

    static std::unique_ptr<SoundService> instance;

    std::map<std::string, Mix_Music *> musicMap;
    std::map<std::string, Mix_Chunk *> sfxMap;
};

The function that I'm calling that breaks the project is just a simple line of testcode:

auto& soundService = SoundService::getInstance();

Here is the conanfile used to declare the required libraries:

from conans import ConanFile, CMake
from conans.tools import os_info

class ModularMagicConan(ConanFile):
    name = "ModularMagic"
    version = "0.1"
    url = "edited out"
    description = "A 2D game"
    settings = "os", "compiler", "build_type", "arch"
    generators = "cmake"

    def requirements(self):
        self.requires("sdl2/2.0.12@bincrafters/stable")         # SDL2, rendering and window creation library
        self.requires("sdl2_image/2.0.5@bincrafters/stable")    # SDL2 image, texture library
        self.requires("sdl2_mixer/2.0.4@bincrafters/stable")    # SDL2 mixer, sound library
        self.requires("gtest/1.10.0")                           # Used for unit testing
        self.requires("box2d/2.4.0")                            # Box2D, physics library


    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def test(self):
        cmake.test()

Anyone familiar with this issue or has any idea what's causing it and how to resolve it?

Bart K
  • 115
  • 1
  • 2
  • 8
  • 1
    Is there no other information at all? My bet is the DLL isn't in the right place. – user253751 Oct 01 '20 at 12:22
  • That seems unlikely to me as I'm using other libraries such as SDL2, SDL2 Image and Box2D that are all referenced in the same way. The editor also doesn't show any errors in the hpp or cpp files. I'll edit my post with the conanfile. – Bart K Oct 01 '20 at 12:26
  • Load your resulting executable into [dependency walker](http://dependencywalker.com/) (use correct architecture though) and check if it fails to load any dependency. – keltar Oct 01 '20 at 18:00

3 Answers3

0

Error 0xC0000135 is usually related to .NET framework issues. It also appears when some windows service can not start.

If I were you, I'd check the system's Event Viewer (I assume you are using Windows OS) to get more details about these. You'll find such application by following this tutorial

xryl669
  • 3,376
  • 24
  • 47
  • I believe I found the error in the Event Viewer, the timestamps are aligned at least. It looks like this: https://puu.sh/GyjW7.png but I'm afraid I'm in a little over my head here. – Bart K Oct 01 '20 at 12:51
  • LLDB is the debugger of LLVM (Clang), the error you're showing is `0xC000005` which is an access violation (equivalent of a Segmentation Fault in Unix, aka memory error). It seems your IDE is not working correctly (CLion) and is unable to launch its own debugger. – xryl669 Oct 01 '20 at 12:55
  • Maybe you should reinstall it, or try launching your software not within the debugger. – xryl669 Oct 01 '20 at 12:57
  • Is that likely that the problem lies with CLion when I can run the debugger just fine without SDL Mixer in my code? – Bart K Oct 01 '20 at 12:59
  • This is plain speculation since I'm not seeing your system, but it breaks as soon as you try to use a *service*. This service might depends on some specific windows' service (related with .NET) that fails to launch and/or crash. In turns, your software is stopped because SDL does not deal with such error correctly (nor does LLDB?). – xryl669 Oct 01 '20 at 13:02
  • To confirm my hypothesis, you can start the Device Manager, locate the main sound device and disable it (so that your system now has no functional audio anymore) and try to run the software. If it starts, it'll fail with some error (no audio, whatever) but it'd start. – xryl669 Oct 01 '20 at 13:06
  • Well the service is question is one that I wrote myself, it's the one of which the header file is posted in my original question. As you can see, it makes no use of other services (nor does it in the cpp). What I find strangest is that the project breaks even though the function I'm calling, getInstance(), doesn't actually make use of any imported SDL_mixer functions or classes. It's just a simple singleton implementation. – Bart K Oct 01 '20 at 13:07
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/222364/discussion-between-xryl669-and-bart-k). – xryl669 Oct 01 '20 at 13:08
0

Well, I don't know if it really counts as an answer, but perhaps it will help others with the same problem. Me and a colleague found this sketchy suggestion somewhere to throw a copy of glib-2.0-0.dll (which you should be able to find in a .conan folder in your :C drive) in System32. This somehow works, I can run my project now. I don't know if this is something that's wrong with SDL_mixer, as it certainly doesn't seem like the right way to solve it, but at least I can work on my project again.

Bart K
  • 115
  • 1
  • 2
  • 8
0

got the same problem in CLion. fixed it by copying all the .dll in SDL2_mixer and put them in the same directory as your .exe file.see picture here

Jacckx
  • 1