slight variation in the way OpenAL and LWJGL find native files

Started by bobjob, December 15, 2010, 08:05:37

Previous topic - Next topic

bobjob

if I use "-Djava.library.path=\C:\Progra~1\Java\LWJGL2\native\windows" on windows 7. lwjgl.dll will be located just fine, but the openAl.dll wont get located.

The reason this is a problem. is when setting dll files at runtime. one way to make sure you get a valid location, is by getting the URL (using getClass().getResource()) then convert it into a URI before getting its path. this (on windows7) will cause the file to start with the '\' character. which in turn means that OpenAL natives wont be found.

dont know if its a bug, because clearly you can just remove the "\" character manually (if you are aware of the problem), but the behaviour is strange.

jediTofu

Couldn't you just specify 2 paths, one with and one without the slash?

-Djava.library.path=\C:\Progra~1\Java\LWJGL2\native\windows;C:\Progra~1\Java\LWJGL2\native\windows
cool story, bro

bobjob

Quote from: jediTofu on December 15, 2010, 09:58:56
Couldn't you just specify 2 paths, one with and one without the slash?

-Djava.library.path=\C:\Progra~1\Java\LWJGL2\native\windows;C:\Progra~1\Java\LWJGL2\native\windows

you only need the 1 "C:\Progra~1\Java\LWJGL2\native\windows". The problem wasnt the command line so much, it was more when including the path at runtime.

When I was using the following code. It seemed strange.
URL url = Thread.currentThread().getContextClassLoader().getResource("native");
String path = url.toURI().getPath();


the workaround was simple enough, just needed to add the line:
if (path.startsWith("/")) path = path.substring(1);

public static void addLWJGLNatives(String nativeFolder) {
	try {
		URL url = Thread.currentThread().getContextClassLoader().getResource(nativeFolder);
		String path = url.toURI().getPath();
		if (path.startsWith("/")) path = path.substring(1);
		addLibDir(path);
	} catch (Exception e) {
		e.printStackTrace();
		JOptionPane.showMessageDialog(null, "error loading natives: " + e.getMessage());
		System.exit(-1);
	}
}


I was mainly curious to know, if anyone knew how the native files are located. And why they wouldn't be found in the same way.