Access violation executing location after using Mix_LoadMUSType_RW

Hello everyone,

After managing loading a png as a SDL_Texture* and a wav as a Mix_Chunk* inside a 7z file with PhysFS, I tried to do the same with music. Everything runs perfectly but after executing:

Mix_PlayMusic(gMusic, -1);

I get the following error:

Exception Thrown
Exception thrown at 0x00007FFB9ADC3BA0 (SDL2.dll) in test.exe: 0xC0000005: Access violation executing location 0x00007FFB9ADC3BA0.

This is the code that I used to load a sound and works perfectly:

Mix_Chunk* loadSound(std::string file)
{
	// Declares sound variable
	Mix_Chunk* loadedSound = NULL;

	// First check if the sound exists
	if (!PHYSFS_exists(file.c_str()))
	{
		printf("Sound not found!");
		loadedSound = NULL;
	}
	else
	{
		// The sound exists so open it
		PHYSFS_file* soundFile = PHYSFS_openRead(file.c_str());

		// Get the lenght of the sound
		int m_size = PHYSFS_fileLength(soundFile);

		// Get the file data.
		uint8_t* m_data = new uint8_t[m_size];

		int length_read = PHYSFS_read(soundFile, m_data, 1, m_size);

		if (length_read != (int)m_size)
		{
			delete[] m_data;

			m_data = 0;

			printf("Sound couldn't be read!");

			loadedSound = NULL;
		}
		PHYSFS_close(soundFile);

		// And this is how you load a sound from a memory buffer with SDL
		SDL_RWops* rw = SDL_RWFromMem(m_data, m_size);

		// Load sound
		loadedSound = Mix_LoadWAV_RW(rw, 0);

		// Free 
		SDL_FreeRW(rw);
	}

	return loadedSound;
}

The only things that change with the loadedMusic function is the return type that is Mix_Music. All references to Mix_Chunk* loadedSound are Mix_Music* loadedMusic and a small name change from soundFile to musicFile. The lines that give later the exception are:

loadedMusic = Mix_LoadMUS_RW(rw, 0);

Or:

loadedMusic = Mix_LoadMUSType_RW(rw, MUS_OGG, 0);

That I suspect is the same as the previous line but I had to try.

I tried it with a wav file and an ogg file, but I read in SDL_mixer.h the following:

/* Load a music file from an SDL_RWop object (Ogg and MikMod specific currently)
Matt Campbell (matt@campbellhome.dhs.org) April 2000 */
extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *src, int freesrc);

So I thought the problem was the wav file but with ogg gives an exception too.

After too many hours spent on this and many headaches, I tried to load the music as a Mix_Chunk* but I don’t think this is a good idea, the test example slows down after loading the full ogg file and not streaming it. But well, it works.

What can be happening? Any ideas?

Thank you for your time.

Regards,

David

PS: more info. How it’s the loadMusic function right now:

// DEBUG this doesn't work so I change it to Mix_Chunk
//Mix_Music* loadMusic(std::string file)
Mix_Chunk* loadMusic(std::string file)
{
	// Declares music variable
	// DEBUG this doesn't work so I change it to Mix_Chunk
	//Mix_Music* loadedMusic = NULL;
	Mix_Chunk* loadedMusic = NULL;

	// First check if the music exists
	if (!PHYSFS_exists(file.c_str()))
	{
		printf("Music not found!");
		loadedMusic = NULL;
	}
	else
	{
		// The music exists so open it
		PHYSFS_file* musicFile = PHYSFS_openRead(file.c_str());

		// Get the lenght of the music
		int m_size = PHYSFS_fileLength(musicFile);

		// Get the file data.
		uint8_t* m_data = new uint8_t[m_size];

		int length_read = PHYSFS_read(musicFile, m_data, 1, m_size);

		if (length_read != (int)m_size)
		{
			delete[] m_data;

			m_data = 0;

			printf("Music couldn't be read!");

			loadedMusic = NULL;
		}
		PHYSFS_close(musicFile);

		// And this is how you load music from a memory buffer with SDL
		SDL_RWops* rw = SDL_RWFromMem(m_data, m_size);

		// Load music
		//DEBUG: this doesn't work so I load the music like a normal sound
		//loadedMusic = Mix_LoadMUS_RW(rw, 0);
		//loadedMusic = Mix_LoadMUSType_RW(rw, MUS_WAV, 0);
		//loadedMusic = Mix_LoadMUSType_RW(rw, MUS_OGG 0);
		loadedMusic = Mix_LoadWAV_RW(rw, 1); // I put it to 1 instead of 0 thinking it would stream and go faster, but I was wrong

		// Free 
		SDL_FreeRW(rw);
	}

	//loadedMusic = Mix_LoadMUS("DATA/beat.ogg");

	return loadedMusic;
}

IDE:

Microsoft Visual Studio Community 2019
Version 16.10.4

OS:

Windows 10 Pro 64 bits, 20H2 version.

Processor:

Intel(R) Core™ i5-4590 CPU @ 3.30GHz 3.30 GHz

RAM: When using the cmd command:

wmic memorychip get capacity, devicelocator, formfactor, manufacturer, memorytype, speed

I get the following information:

Capacity: 8589934592
DeviceLocator: DIMM_A1
FormFactor: 8 (which is DIMM)
Manufacturer: Kingston
MemoryType: 24 (which is DDR3)
Speed: 1600

If you need any more information please tell me. I’ll tell you and I’ll add it here

I’m having this exact same issue, did you ever figure out a solution, or did you end up just using Chunks instead of Music? I’m finding that Load_MUS directly works fine, but using Load_MUS_RW from a file loaded using PHYSFS does not work.

1 Like

Hello,

Never found a solution and ended up using Chunks.

Regards,

David

1 Like

Can you report a bug here, with a link to the data files you’re using?