LibGDX - Unable to allocate audio buffers

Hi guys

I’m working on my game over screen that simply allows the player to see their score, play again or exit the game. This is all working great apart from thing, the music is causing the game to crash when switching to my main game screen.

I’ve narrowed it down to the

Assets.gameMusic.play

Without this, the game reloads perfectly and starts a brand new game. The music is inside the game show method and i’m making sure to stop the music and dispose of it before the screen changes. I then reload the music if the player clicks on play again button and that is what the issue is.

Any idea on how to solve this? D: if you need anything else such as more code or info then just let me know! :slight_smile:

Thanks :slight_smile:

This should help haha :smiley: Clicky.
Good luck!

Already searched for over an hour on Google, no luck in fixing it. Was hoping someone here had fixed it before

This isn’t helpful. :emo:
There’s nothing wrong with asking him if he at least tried to research the subject before asking, but instantly implying that he made no research at all is rude.

Personally I don’t use LibGDX too much but if you attach the LibGDX source code in Eclipse to the LibGDX JAR then you will be able to see what’s going on inside the LibGDX classes when debugging and that could be helpful. Also could you share the music loading part of your code? Because it’s very likely that is what’s causing the issue. :slight_smile:

Hi Panda

I shall look into the source and see if I can find anymore info out.

The music loading code is as followed:

public static void loadSounds(){ // This is part of the Assets class where I keep all my textures/sounds/effects etc.
gameMusic = Gdx.audio.newMusic(Gdx.files.internal("542284_ScienceBlasterAiler.mp3")); loading in the music here
}

The following code is part of the GameOverScreen. If the button is pressed then reloads the music as I disposed it in the previous screen

playAgainButton.addListener(new InputListener(){ // Listener for button events
			public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { 
				
				Assets.mainMenuClick.play(); // Play the menu button sound if clicked
				Assets.loadSounds(); // Reload the sounds here

				dispose(); // Manually call the dispose as changing screens calls only the hide method.
				game.setScreen(new GameScreen(game)); // Change the screen to the main game.
				
				return true;
			}
		});

Sorry, didn’t meant to be rude. But there are really a lot of people out there that have just the same problem as you do.

I use LibGDX personally myself so i will try to help.
Does dispose dispose any sound/music? Cause if some music gets disposed when it’s playing, the program will crash.
Maybe Assets.loadSounds(); is causing the issue? (is called directly after mainMenuClick.play(); )
Can you post the full stack trace?
Also, you can consider a alternative (copied from my project) MusicManager.java SoundManager.java LRUCache.java
Hope i helped :wink:

Yes, the dispose gets disposes of my music but I removed that and the problem is still the same.

The Assets.loadSounds actually only contains the music for the game, I should rename that method to ‘loadMusic’ xD so that isn’t the issue.

If I remove the .play() method for the music inside my main GameScreens’ show method, the music won’t play of course, but the program doesn’t crash. So it seems an issue with that, I’m not on my main PC right now so I will grab the stack trace when I get back on :D!