Skip to content

Commit

Permalink
Lower java.library.path's priority for libraries not bundled with LWJ…
Browse files Browse the repository at this point in the history
…GL. Close LWJGL#291
  • Loading branch information
Spasi committed Mar 7, 2017
1 parent 21556f7 commit b8d463b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/core/src/main/java/org/lwjgl/openal/ALC.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public long getFunctionAddress(long handle, ByteBuffer functionName) {
* @param libName the native library name
*/
public static void create(String libName) {
SharedLibrary OPENAL = Library.loadNative(ALC.class, libName);
SharedLibrary OPENAL = Library.loadNative(ALC.class, libName, true);
try {
create(new SharedLibraryAL(OPENAL));
} catch (RuntimeException e) {
Expand Down
25 changes: 21 additions & 4 deletions modules/core/src/main/java/org/lwjgl/system/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ public static SharedLibrary loadNative(Class<?> context, String name, boolean bu
}
}

// Use method 4 before 3 for libraries not bundled with LWJGL.
if ( !bundledWithLWJGL ) {
lib = loadNativeFromSystem(libName);
if ( lib != null )
return lib;
}

// METHOD 3: System.loadLibrary (emulated)
{
if ( Configuration.EMULATE_SYSTEM_LOADLIBRARY.get(false) ) {
Expand Down Expand Up @@ -266,16 +273,26 @@ public static SharedLibrary loadNative(Class<?> context, String name, boolean bu
}

// METHOD 4: system-specific
if ( bundledWithLWJGL ) {
lib = loadNativeFromSystem(libName);
if ( lib != null )
return lib;
}

printError(bundledWithLWJGL);
throw new UnsatisfiedLinkError("Failed to locate library: " + libName);
}

private static SharedLibrary loadNativeFromSystem(String libName) {
SharedLibrary lib;
try {
lib = apiCreateLibrary(libName);
apiLog("\tLoaded from system paths");
return lib;
} catch (UnsatisfiedLinkError e) {
lib = null;
apiLog(String.format("\t%s not found in system paths", libName));
}

printError(bundledWithLWJGL);
throw new UnsatisfiedLinkError("Failed to locate library: " + libName);
return lib;
}

private static SharedLibrary loadNative(Class<?> context, String libName, Configuration<String> property) {
Expand Down

0 comments on commit b8d463b

Please sign in to comment.