[CLOSED] Intermittent "Could not locate OpenAL library"

Started by Elviz, March 16, 2010, 07:53:57

Previous topic - Next topic

Elviz

Setup:

  • Windows XP, 32-bit
  • Sun's JRE 6 Update 18
  • LWJGL 2.3

Calls to AL.create intermittently fail, even though the native library path is correct. In the course of looking for a way to reliably reproduce the problem, I came up with the following test case:

import org.lwjgl.*;
import org.lwjgl.openal.*;

public final class AudioTest {
  public static void main(String[] args) {
    for (int idx = 0; idx < 100000; idx++) {
      System.out.println(idx);
      
      try {
        AL.create ();
        AL.destroy();
      } catch (LWJGLException ex) {
        System.err.println(idx);
        ex.printStackTrace();
      }
      
      try {
        Thread.sleep(5);
      } catch (InterruptedException ex) {
      }
    }
  }
}


This just creates and destroys OpenAL instances non-stop. Generally, it works, however, and that's the point, when I click on a button in the Windows taskbar (holding down the mouse) while the program is running, exceptions start occurring:

org.lwjgl.LWJGLException: Could not locate OpenAL library.
	at org.lwjgl.openal.AL.create(AL.java:153)
	at org.lwjgl.openal.AL.create(AL.java:104)
	at org.lwjgl.openal.AL.create(AL.java:191)
	at AudioTest.main(AudioTest.java:10)


In other words, if the user happens to be switching applications using the taskbar while the LWJGL app is trying to initialize OpenAL, AL.create() will fail and there'll be no sound.

Matzon

Quote from: Elviz on March 16, 2010, 07:53:57
In other words, if the user happens to be switching applications using the taskbar while the LWJGL app is trying to initialize OpenAL, AL.create() will fail and there'll be no sound.

strange issue... anywhere on the taskbar?

Elviz

Quote from: Matzon on March 16, 2010, 08:36:36strange issue... anywhere on the taskbar?

No, it just happens when clicking on the buttons representing the open applications.

The debug output says:

Failed to load C:\PathToTheNativeBinaries\OpenAL32.dll: Could not open ALC device

princec

I've noticed this intermittent bug for at least a year now, maybe even longer. It looks like an OpenAL issue but it's hard to be sure.

Cas :)

Matzon

I have tracked this issue down to alcOpenDevice failing, if the calling threads process is not the foreground window.
This has to do with using the dsound backend setting the cooperative level using the foreground window (it has no supplied hwnd, and it can't get it).

dsound.c:
  hr = IDirectSound_SetCooperativeLevel(pData->lpDS, GetForegroundWindow(), DSSCL_PRIORITY);


We cannot reliably fix this - nor can OpenAL.

My best suggestions is to check when OpenAL creation fails, if Display.isActive is false too - then thats probably the reason.

You could then busy wait or notify the user... at any rate, its probably not something we can fix internally in lwjgl.

Elviz

Yeah, perhaps I'll use some kind of workaround.

Thanks for looking into this.

princec

Basically then - it can probably be retried and will probably work eventually when the window gets into the foreground?

Cas :)

Matzon

yes - but if the user is doing something else - then you'd be busy waiting until then...
You could probably also wait to create AL until you get the first mouse input?