summaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2013-06-18 01:41:30 +0200
committerSven Gothel <[email protected]>2013-06-18 01:41:30 +0200
commit4feb65517ae4a4e2b9b04cdfc4b85582cb8b9784 (patch)
treeb043abfa0ae00ed3915862730e35ef15c9f7f630 /src/java
parente18771cc020f6fd42f6427540c079e48699ab310 (diff)
Robostness: Catch Throwables on NativeLibrary.open(..) and be verbose in DEBUG mode ; DynamicLinker: Add 'String getLastError()'.
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/jogamp/common/os/DynamicLinker.java1
-rw-r--r--src/java/com/jogamp/common/os/NativeLibrary.java25
-rw-r--r--src/java/jogamp/common/os/UnixDynamicLinkerImpl.java5
-rw-r--r--src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java5
4 files changed, 29 insertions, 7 deletions
diff --git a/src/java/com/jogamp/common/os/DynamicLinker.java b/src/java/com/jogamp/common/os/DynamicLinker.java
index 32aa7eb..b1671b9 100644
--- a/src/java/com/jogamp/common/os/DynamicLinker.java
+++ b/src/java/com/jogamp/common/os/DynamicLinker.java
@@ -51,4 +51,5 @@ public interface DynamicLinker {
public long lookupSymbol(long libraryHandle, String symbolName);
public long lookupSymbolGlobal(String symbolName);
public void closeLibrary(long libraryHandle);
+ public String getLastError();
}
diff --git a/src/java/com/jogamp/common/os/NativeLibrary.java b/src/java/com/jogamp/common/os/NativeLibrary.java
index bfc5b07..3009ef3 100644
--- a/src/java/com/jogamp/common/os/NativeLibrary.java
+++ b/src/java/com/jogamp/common/os/NativeLibrary.java
@@ -186,13 +186,26 @@ public class NativeLibrary implements DynamicLookupHelper {
for (Iterator<String> iter = possiblePaths.iterator(); iter.hasNext(); ) {
String path = iter.next();
if (DEBUG) {
- System.err.println("NativeLibrary.open(): Trying to load " + path);
+ System.err.println("NativeLibrary.open(global "+global+"): Trying to load " + path);
}
long res;
- if(global) {
- res = dynLink.openLibraryGlobal(path, DEBUG);
- } else {
- res = dynLink.openLibraryLocal(path, DEBUG);
+ try {
+ if(global) {
+ res = dynLink.openLibraryGlobal(path, DEBUG);
+ } else {
+ res = dynLink.openLibraryLocal(path, DEBUG);
+ }
+ } catch (Throwable t1) {
+ if( DEBUG ) {
+ System.err.println("NativeLibrary.open: Catched "+t1.getClass().getSimpleName()+": "+t1.getMessage());
+ String errstr;
+ try {
+ errstr = dynLink.getLastError();
+ } catch (Throwable t2) { errstr=null; }
+ System.err.println("NativeLibrary.open: Last error "+errstr);
+ t1.printStackTrace();
+ }
+ res = 0;
}
if (res != 0) {
return new NativeLibrary(res, path, global);
@@ -200,7 +213,7 @@ public class NativeLibrary implements DynamicLookupHelper {
}
if (DEBUG) {
- System.err.println("NativeLibrary.open(): Did not succeed in loading (" + windowsLibName + ", " + unixLibName + ", " + macOSXLibName + ")");
+ System.err.println("NativeLibrary.open(global "+global+"): Did not succeed in loading (" + windowsLibName + ", " + unixLibName + ", " + macOSXLibName + ")");
}
// For now, just return null to indicate the open operation didn't
diff --git a/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java b/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java
index e4cdbda..7675977 100644
--- a/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java
+++ b/src/java/jogamp/common/os/UnixDynamicLinkerImpl.java
@@ -71,5 +71,8 @@ public class UnixDynamicLinkerImpl implements DynamicLinker {
public void closeLibrary(long libraryHandle) {
dlclose(libraryHandle);
}
-
+
+ public String getLastError() {
+ return dlerror();
+ }
}
diff --git a/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java b/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java
index 17d4adc..884ac39 100644
--- a/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java
+++ b/src/java/jogamp/common/os/WindowsDynamicLinkerImpl.java
@@ -66,4 +66,9 @@ public class WindowsDynamicLinkerImpl implements DynamicLinker {
FreeLibrary(libraryHandle);
}
+ public String getLastError() {
+ final int err = GetLastError();
+ return "Last error: 0x"+Integer.toHexString(err)+" ("+err+")";
+ }
+
}