Create only one AL instance

When TestAmbient is executed by TestChooser,

trying to create 2 AL instance and failed with error below.



java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:597)

at jme3test.TestChooser$2.run(TestChooser.java:271)

at java.lang.Thread.run(Thread.java:619)

Caused by: java.lang.IllegalStateException: Only one OpenAL context may be instantiated at any one time.

at org.lwjgl.openal.AL.create(AL.java:115)

at org.lwjgl.openal.AL.create(AL.java:104)

at org.lwjgl.openal.AL.create(AL.java:203)

at com.jme3.audio.lwjgl.LwjglAudioRenderer.initialize(LwjglAudioRenderer.java:98)

at jme3test.audio.AudioApp.(AudioApp.java:55)

at jme3test.audio.TestAmbient.(TestAmbient.java:40)

at jme3test.audio.TestAmbient.main(TestAmbient.java:48)



[patch]

Index: src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java

===================================================================

— src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java (revision 6302)

+++ src/lwjgl-oal/com/jme3/audio/lwjgl/LwjglAudioRenderer.java (working copy)

@@ -94,7 +94,9 @@



public void initialize(){

try{

  •        AL.create();<br />
    
  •        if (!AL.isCreated()) {<br />
    
  •            AL.create();<br />
    
  •        }<br />
    

}catch (OpenALException ex){

logger.log(Level.SEVERE, "Failed to load audio library", ex);

audioDisabled = true;

[/patch]

The library / dll for openal (the sound) can only be used by one process at a time. It seems as if you are running this from the same directory more than once, thus causing the problem. I’m not a JME expert but if theory you should be able to build this project, copy it to another folder. Then build /run the project for one instance, then just run the jar from the copied folder as the other instance.



EDIT:

After rereading, it looks like you are only trying to run the one instance but getting an error. Sorry that wasn’t clear to me right away, it is still early ;). You might already have a previous example open in memory that is using the sound resource. Try killing javaw.exe or if you are using another OS killing the java processes, then start again.

Thank you for the answer. :smiley:

As you said, this approach seems to be inappropriate if there should be only one AudioRenderer.



There is no other java processes because executing TestAmbient class directly causes no problem.

I need to find why TestChooser calls the method twice.