2

I have the following sound loading function:

bool Sound::load(const char* fileName)
{
    sound = Mix_LoadWAV(fileName);
    if (sound == nullptr)
    {
        std::cout << "Failed to load sound at path: " << fileName << "SDL_mixer error: " << Mix_GetError();
        return false;
    }

return true;
}

In Dev-C++, this works, fine. I wanted to use another IDE, so I started using Visual Studio 2017, and configured SDL2 for it. However, when I run this code, from the moment Mix_LoadWAV is called, Visual studio gives the following: https://i.stack.imgur.com/HfPeY.jpg

I have searched alot on the internet, but I could not find anything useful that worked for me.

EDIT: as per request, I created a minimal example that still produces the same error.

#include "SDL2\SDL_mixer.h"
#include "SDL2\SDL.h"

#include <iostream>

#undef main

class SoundTest
{
private:
Mix_Chunk* sound = nullptr;
public:
bool load(const char* fileName)
{
    sound = Mix_LoadWAV(fileName);

    if (sound == nullptr)
    {
        std::cout << "Failed to load sound at path: " << fileName << "SDL_mixer error: " << Mix_GetError();
        return false;
    }

    return true;
}
};

SDL_Window *window = nullptr;

int main(int argc, char** argv)
{
    SDL_Init(SDL_INIT_EVERYTHING);

    window = SDL_CreateWindow("Sound bug? ", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 300, 300, SDL_WINDOW_SHOWN);

    Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 2048);

    SoundTest sound;
    sound.load("audio/soundEffect.wav");
    while (true)
    {
        //Do fun stuff with the sound
    }

    return 0;
}
MivVG
  • 679
  • 4
  • 16
  • @genpfault I edited it, and it still gives the same error. – MivVG Oct 23 '17 at 16:46
  • 1
    Where's your `Mix_Init()` call? Why are you `#undef`ing `main` and not calling [`SDL_SetMainReady()`](https://wiki.libsdl.org/SDL_SetMainReady)? – genpfault Oct 23 '17 at 17:46
  • #undef main is there because of the macro stuff SDL does to main. If SDL_SetMainReady() does that, I had never heard of that function. About Mix_Init(), Is that required? up to now, I have always used Mix_OpenAudio() without problems. – MivVG Oct 23 '17 at 19:37
  • [This](https://pastebin.com/W3EQBHWE) is working fine for me with fresh [SDL 2.0.7](https://www.libsdl.org/release/SDL2-devel-2.0.7-VC.zip) and [SDL2_mixer 2.0.1](https://www.libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.1.zip) x86 development binaries in VS2015. – genpfault Oct 23 '17 at 20:07
  • I have reinstalled SDL, but your code does not work for me. I am using VS2017 though. Maybe that can be the problem? See [this](https://imgur.com/a/YhpNw) For a screenshot. – MivVG Oct 24 '17 at 14:40
  • I have exactly the same SDL versions as you – MivVG Oct 25 '17 at 11:19

0 Answers0