LWJGL Forum

Archive => Resolved Bugs/RFE => Topic started by: Elviz on March 16, 2010, 07:53:57

Title: [CLOSED] Intermittent "Could not locate OpenAL library"
Post by: Elviz on March 16, 2010, 07:53:57
Setup:

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.
Title: Re: Intermittent "Could not locate OpenAL library"
Post by: Matzon on March 16, 2010, 08:36:36
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?
Title: Re: Intermittent "Could not locate OpenAL library"
Post by: Elviz on March 16, 2010, 09:53:46
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
Title: Re: Intermittent "Could not locate OpenAL library"
Post by: princec on March 16, 2010, 10:38:03
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 :)
Title: Re: Intermittent "Could not locate OpenAL library"
Post by: Matzon on April 05, 2010, 19:58:44
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.
Title: Re: Intermittent "Could not locate OpenAL library"
Post by: Elviz on April 07, 2010, 14:55:20
Yeah, perhaps I'll use some kind of workaround.

Thanks for looking into this.
Title: Re: Intermittent "Could not locate OpenAL library"
Post by: princec on April 08, 2010, 10:23:23
Basically then - it can probably be retried and will probably work eventually when the window gets into the foreground?

Cas :)
Title: Re: Intermittent "Could not locate OpenAL library"
Post by: Matzon on April 08, 2010, 10:34:56
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?