Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenALMusic - Unable to allocate audio buffers. AL Error: 40963 #5318

Open
1 of 7 tasks
someguy233 opened this issue Jul 20, 2018 · 8 comments
Open
1 of 7 tasks

OpenALMusic - Unable to allocate audio buffers. AL Error: 40963 #5318

someguy233 opened this issue Jul 20, 2018 · 8 comments

Comments

@someguy233
Copy link
Contributor

Issue details

This is a really elusive bug to reproduce. From the crash reports I receive from players, it crops up randomly if one does pause(), setPosition(), play() or dispose() repeatedly. I'm not sure if its hardware related or due to some timing issue. While I could reproduce it consistently with a code similar to #5316 , I'm pretty sure it is not related.

Reproduction steps/code

Just the render() of an empty ApplicationListener:

            Music music = null;

            @Override
            public void render() {
                int frameNumber = (int)Gdx.graphics.getFrameId();
                Gdx.app.log("CRASH", "Frame " + frameNumber);
                switch (frameNumber) {
                    case 0:
                        // Frame 1
                        music = Gdx.audio.newMusic(Gdx.files.external("any_audio_file.ogg"));
                        music.play();
                        break;

                    case 1:
                        // Frame 2
                        music.setPosition(26.300f);     // must be within at least 200ms from the end
                        break;

                    case 2:
                        // Frame 3
                        music.setPosition(26.300f);     // must be within at least 200ms from the end
                        break;

                    case 3:
                        // Frame 4
                        music.dispose();
                        break;

                    case 4:
                        // Frame 5
                        music = Gdx.audio.newMusic(Gdx.files.external("any_audio_file.ogg"));
                        music.play();       // Crashes here
                        break;
                }
            }

Version of LibGDX and/or relevant dependencies

1.9.9-SNAPSHOT

Stacktrace

com.badlogic.gdx.utils.GdxRuntimeException: Unable to allocate audio buffers. AL Error: 40963
	at com.badlogic.gdx.backends.lwjgl.audio.OpenALMusic.play(OpenALMusic.java:83)
	at game27.DesktopMain$2.render(DesktopMain.java:270)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:225)
	at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)

Please select the affected platforms

  • Android
  • iOS (robovm)
  • iOS (MOE)
  • HTML/GWT
  • Windows
  • Linux
  • MacOS
@mgsx-dev
Copy link
Contributor

i'm able to reproduce with the libgdx MusicTest.

First case :

  • run WAV example with looping disabled
  • play with the cursor back and forth several times
  • let the song finish
  • you can't start the song (it fails silently)

Second case :

  • run WAV example with looping disabled
  • play with the cursor back and forth several times
  • change the music (mp3 or ogg) before it finish
  • it crashes : Unable to allocate audio buffers. AL Error: 40963

libgdx code properly unqueue buffers but as per OpenAL doc : The unqueue operation will only take place if all n buffers can be removed from the queue. maybe OpenAL can't cancel some running buffers which lead to a kind of accumultation due to allocation/free frequency.

Maybe those kind of use are extreme and maybe Sound should be used instead.

@NikolajPagh
Copy link

I have the exact same error on Windows :( - Any news on this ?

Scenario:

  • Playing Music one
  • Player selects some action
  • Stopping Music one
  • Start Music two
  • Crash with Unable to allocate audio buffers. AL Error: 40963

@Frotty
Copy link
Contributor

Frotty commented Aug 3, 2020

Also happens with LWJGL3, haven't found a solution thus far.

@tomcashman
Copy link
Contributor

According to this thread the buffer needs to be processed before alSourceUnqueueBuffers can be called and from what I can tell the current OpenALMusic implementation it doesn't check for this.

@tomcashman
Copy link
Contributor

I've been able to reproduce this in a simple test. If you click and then leave the music running when it gets to the end of the first track the crash will occur.

package com.badlogic.gdx.tests;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.tests.utils.GdxTest;

public class MultiMusicTest extends GdxTest {

	Music music1, music2;

	SpriteBatch batch;
	BitmapFont font;

	float timer;

	@Override
	public void create() {
		batch = new SpriteBatch();
		font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);

		music1 = Gdx.audio.newMusic(Gdx.files.internal("data/60bpm.mp3"));
		music1.setLooping(true);
		music2 = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.mp3"));
		music2.setLooping(true);
	}

	@Override
	public void render() {
		timer += Gdx.graphics.getDeltaTime();

		if(timer > 1f) {
			if(MathUtils.isZero(music1.getVolume())) {
				music1.setVolume(1f);
				music1.stop();
				music2.play();
			}
			if(MathUtils.isZero(music2.getVolume())) {
				music2.setVolume(1f);
				music2.stop();
				music1.play();
			}
			music1.setVolume(music1.getVolume() - 0.1f);
			music2.setVolume(music2.getVolume() - 0.1f);
			timer = 0f;
		}

		if (Gdx.input.justTouched()) {
			if(!music1.isPlaying() && !music2.isPlaying()) {
				music1.play();
			} else if(music1.isPlaying()) {
				music1.stop();
				music2.play();
			} else {
				music2.stop();
				music1.play();
			}
		}

		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
		batch.begin();
		font.draw(batch, music1.isPlaying() ? "Music 1 playing" : "Music 1 not playing", 128, 32);
		font.draw(batch, music2.isPlaying() ? "Music 2 playing" : "Music 2 not playing", 128, 64);
		batch.end();
	}

	@Override
	public void resume () {
		System.out.println(Gdx.graphics.getDeltaTime());
	}

	@Override
	public void dispose() {
		music1.dispose();
		music2.dispose();
	}
}

@tomcashman
Copy link
Contributor

It seems the specific OpenAL error is:
AL_INVALID_VALUE an invalid value was passed to an OpenAL function

Looking in the OpenAL API docs, alGenBuffers only generates this error when:
The buffer array isn't large enough to hold the number of buffers requested.

But if I breakpoint before alGenBuffers on line 80 in OpenALMusic, the buffer value is of size 3 as requested.

@NathanSweet
Copy link
Member

@tomcashman Your crash happens because music1.setVolume(music1.getVolume() - 0.1f); sets the volume below zero. This sets the error state but it is not checked. Later alGetError gives an error.

Since we don't check alGetError everywhere, we should call it to clear the error before we do an action where we check it afterward. This is better but isn't clear if it will help the other problems in this issue.

Also, we should check the volume parameter is in range.

NathanSweet added a commit that referenced this issue Apr 21, 2021
@crykn crykn changed the title LWJGL2 OpenALMusic - Unable to allocate audio buffers. AL Error: 40963 OpenALMusic - Unable to allocate audio buffers. AL Error: 40963 Jul 14, 2021
@cebess
Copy link

cebess commented Aug 9, 2021

I have had this happen when I added a fade out and then volume was set to less than zero. Once ensured the volume never went below zero -- things worked as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants