diff options
author | Michael Bien <[email protected]> | 2011-02-04 22:33:18 +0100 |
---|---|---|
committer | Michael Bien <[email protected]> | 2011-02-04 22:33:18 +0100 |
commit | aec6036ac7c70c905573c5f5f133646555e4a58e (patch) | |
tree | 60a53c782502c2efdfa46b56eb20aaaca6a656da | |
parent | ad554ae820ca353a1796bd750b669c1a00546341 (diff) |
device names no longer corrupted on windows.
-rw-r--r-- | src/com/jogamp/opencl/CLInfoAccessor.java | 2 | ||||
-rw-r--r-- | src/com/jogamp/opencl/util/CLUtil.java | 11 |
2 files changed, 9 insertions, 4 deletions
diff --git a/src/com/jogamp/opencl/CLInfoAccessor.java b/src/com/jogamp/opencl/CLInfoAccessor.java index 2447760..08f8d8a 100644 --- a/src/com/jogamp/opencl/CLInfoAccessor.java +++ b/src/com/jogamp/opencl/CLInfoAccessor.java @@ -77,7 +77,7 @@ abstract class CLInfoAccessor { checkForError(ret, "error while asking for info string"); int clSize = (int)sizeBuffer.get(0); - byte[] array = new byte[clSize-1]; // last char is always null + byte[] array = new byte[clSize]; buffer.get(array).rewind(); return CLUtil.clString2JavaString(array, clSize); diff --git a/src/com/jogamp/opencl/util/CLUtil.java b/src/com/jogamp/opencl/util/CLUtil.java index 3d555cb..371c493 100644 --- a/src/com/jogamp/opencl/util/CLUtil.java +++ b/src/com/jogamp/opencl/util/CLUtil.java @@ -49,16 +49,21 @@ import java.util.Map; public class CLUtil { public static String clString2JavaString(byte[] chars, int clLength) { - return clLength==0 ? "" : new String(chars, 0, clLength-1); + + // certain char queries on windows always claim to have a fixed length + // e.g. (clDeviceInfo(CL_DEVICE_NAME) is always 64.. but luckily they are 0 terminated) + while(clLength > 0 && chars[--clLength] == 0); + + return clLength==0 ? "" : new String(chars, 0, clLength+1); } public static String clString2JavaString(ByteBuffer chars, int clLength) { if (clLength==0) { return ""; }else{ - byte[] array = new byte[clLength-1]; // last char is always null + byte[] array = new byte[clLength]; chars.get(array).rewind(); - return new String(array, 0, clLength-1); + return clString2JavaString(array, clLength); } } |