Bug 251 : using loadSound() many times can cause LineUnavailableException
Last modified: 2008-08-16 15:36




Status:
RESOLVED
Resolution:
WONTFIX -
Priority:
P3
Severity:
normal

 

Reporter:
fry
Assigned To:
fry

Attachment Type Created Size Actions
fix and example for testing application/zip 2005-12-18 12:08 22.40 KB

Description:   Opened: 2005-12-18 12:06
submission from dan shiffman:

If loadSound() is called more than 32 times (actual limit may vary),
this error message will result:

javax.sound.sampled.LineUnavailableException: No Free Voices
at com.sun.media.sound.MixerClip.nSetup(Native Method)

I've solved the problem by adding a destroy() method to PSound2, which
"flushes" and "closes" the clip.

/**
* destroy method, this is new, I have no idea if I'm doing this correctly
*/
public void destroy() {
try {
clip.flush();
clip.close();
} catch (Exception e) {
System.out.println("Error destroying clip: " + e);
}
}

I can now do this infinitely without any error:

void mousePressed() {
println("Loading 32 new sounds. . .");
for (int i = 0; i < sounds.length; i++) {
sounds[i].destroy();
sounds[i]= loadDSound("success.wav");
}
}
Additional Comment #1 From fry 2005-12-18 12:08
edit]
fix and example for testing
Additional Comment #2 From fry 2005-12-18 12:09
implemented using finalize() for 0099, but this probably won't be enough to
do it properly since finalize is called so inconsistently and who knows if
things are properly getting de-referenced.
Additional Comment #3 From fry 2008-08-16 15:36
Closing bug since sound has been removed from the core API.