Can't create sound second time?

Here is a bit of the source:


public class Sound extends Point {
    ...
	public Sound(String name) {
        ...
		source = alGenSources();
		alSourcei(source, AL_BUFFER, buffers.get(name));
		alDeleteSources(source);
		source = alGenSources();
		alSourcei(source, AL_BUFFER, buffers.get(name));
		
		setDistanceModel(INVERSE);
		setDirection(0);
		
		int error = alGetError();
		if (error != AL_NO_ERROR) {
			throw new RGException(RGException.SOUND, alGetString(error));
		}
	}
    ...
	public void destroy() {
		alDeleteSources(source);
	}

But when I create a sound with the file “laser.wav”, then let it play (let it go, let it go), then destroy it, then create another sound with “laser.wav”… It throws this error:


Exception in thread "main" com.redmintie.redgame.core.RGException: [SOUND] Invalid Name

I had a look into it and this error is caused by:


alSourcei(source, AL_BUFFER, buffers.get(name));

Is OpenAL deleting the buffer? Does anybody know what is happening? Sry for so much code… I tried recreating it in a simpler version but I wasn’t able to… also, this is my first time trying OpenAL (it is amazing btw)

Thx in advance…

EDIT: just found out that you don’t actually have to let the sound play out… even if you don’t let it play out or dont event start it playing at all… It will still create the same error

I haven’t worked with OpenAL, but I am curious about one aspect of your question, and it might lead to a solution.

With Clip (in javax.sound.sampled), a common newbie practice is to reload the sound anew from the source file with each playback. They don’t realize that the Clip was designed to only be loaded once, and that there are methods to reposition the “playback head” of the sound back to the start, and replay it.

Is this possible with the sounds you are trying to play? It seems really inefficient to me to have to destroy and reload a sound for the simple task of playing it more than once. Chances are, once it is in memory, there is a way to reset it to the beginning and restart.

Interesting… But the source doesn’t contain all the data… The data is cached (as an openAL buffer) and put into each source made…

but maybe after playing, I might have to rewind the buffer?

If that doesn’t work I can just have it cached as a format, ByteBuffer data, and frequency… Then load it into a new buffer and add that buffer to the source…

Nope… not working… Just found out that “Invalid Name” is coming from:

source = alGenSources()

What would be the “Invalid Name”? It can’t be the limit… I only create 2 sources… What is happening here?

FINALLY FIGURED IT OUT!!!

It had nothing to do with OpenAL… for some reason my entities where still updating for one last frame after they got removed…
So an error was created but because I only check for errors when creating the sound, the error popped up there…

Now I have to figure out why my entities are updating…