crash when LineUnavailableException is thrown

Hi!

On my PC at work, I have no sound. When I launch TUER on it, I get this message:
Error: Audio Device unavailable

A LineUnavailableException is thrown here:

asdl[i] = (SourceDataLine)mixer.getLine(infoLine);
if (i >= iMusic)
     asdl[i].open(fmtLine, 500000+64000+4096); // not used
else
     asdl[i].open(fmtLine, maxSoundLength+4096);

Is there a way of checking if the line is available before calling the method “open”?

Why not just catching the exception and then disable sound?

I tried to do it but this exception is wrapped in an Error :frowning: then it doesn’t work.

Hm, that is strange. What is the Error exactly, do you have a stacktrace?

Then catch the Error, or Throwable

It is strange… now, catching the LineUnavailableException seems to be enough whereas it wasn’t the case some weeks ago. I will try to reproduce the problem later. The audio chip is really not reliable here.

That was the stack trace:

Error: Audio Device Unavailable
javax.sound.sampled.LineUnavailableException: Audio Device Unavailable
at com.sun.media.sound.HeadspaceMixer.nResume(Native Method)
at com.sun.media.sound.HeadspaceMixer.implOpen(HeadspaceMixer.java:346)
at com.sun.media.sound.AbstractMixer.open(AbstractMixer.java:286)
at com.sun.media.sound.AbstractMixer.open(AbstractMixer.java:323)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:103)
at com.sun.media.sound.MixerSourceLine.open(MixerSourceLine.java:39)
at main.SoundSystem.openSound(SoundSystem.java:572)
at main.GameController.openSound(GameController.java:463)
at main.GameController.(GameController.java:109)
at connection.GameServiceProvider.main(GameServiceProvider.java:88)

[quote]Error: Audio Device Unavailable
[/quote]
Are you sure this was a java error, and not something that was logged by your game when the LineUnavailableException was thrown? (since the error message is the same as the exception message)

That just looks like an ordinary Exception to me. Yep, just googled it - it’s an ordinary checked Exception.

Cas :slight_smile:

Yes it is, but goussej mentioned it was somehow wrapped in an error so that he couldn’t catch it.
Anyway, since it works now, I’m guessing it was a different problem and the ‘Error’ was a red herring.

The error doesn’t come from my game. The only class that handles the sound doesn’t create such logs. You can check it by deactivating the sound, modifying my source code (remove the try/catch close in main.SoundSystem) and compile all, the default ANT target generates a JAR file, there is another target to start the game.