summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/jogamp/opencl/CLContext.java16
-rw-r--r--test/com/jogamp/opencl/HighLevelBindingTest.java27
2 files changed, 39 insertions, 4 deletions
diff --git a/src/com/jogamp/opencl/CLContext.java b/src/com/jogamp/opencl/CLContext.java
index a50bf628..07b59d9e 100644
--- a/src/com/jogamp/opencl/CLContext.java
+++ b/src/com/jogamp/opencl/CLContext.java
@@ -160,7 +160,11 @@ public class CLContext extends CLObject implements CLResource {
if(devices != null && devices.length != 0) {
pb = PointerBuffer.allocateDirect(devices.length);
for (int i = 0; i < devices.length; i++) {
- pb.put(i, devices[i].ID);
+ CLDevice device = devices[i];
+ if(device == null) {
+ throw new IllegalArgumentException("device at index"+i+" was null.");
+ }
+ pb.put(i, device.ID);
}
}
long context = CLPlatform.getLowLevelCLInterface().clCreateContext(properties, pb, null, null, status);
@@ -463,13 +467,17 @@ public class CLContext extends CLObject implements CLResource {
}
protected static long toDeviceBitmap(Type[] deviceTypes) {
- long type = 0;
+ long bitmap = 0;
if (deviceTypes != null) {
for (int i = 0; i < deviceTypes.length; i++) {
- type |= deviceTypes[i].TYPE;
+ Type type = deviceTypes[i];
+ if(type == null) {
+ throw new IllegalArgumentException("Device type at index "+i+" was null.");
+ }
+ bitmap |= type.TYPE;
}
}
- return type;
+ return bitmap;
}
@Override
diff --git a/test/com/jogamp/opencl/HighLevelBindingTest.java b/test/com/jogamp/opencl/HighLevelBindingTest.java
index 33cce0b5..35c13261 100644
--- a/test/com/jogamp/opencl/HighLevelBindingTest.java
+++ b/test/com/jogamp/opencl/HighLevelBindingTest.java
@@ -200,6 +200,33 @@ public class HighLevelBindingTest {
assertEquals(deviceCount, c.getDevices().length);
c.release();
+
+ //Exceptions
+ try{
+ CLContext.create((CLDevice)null);
+ fail("create with null device");
+ }catch(IllegalArgumentException ex) {
+ // expected
+ }
+ try{
+ CLContext.create((CLDevice.Type)null);
+ fail("create with null CLDevice.Type");
+ }catch(IllegalArgumentException ex) {
+ // expected
+ }
+ try{
+ CLContext.create((CLPlatform)null, (CLDevice)null);
+ fail("create with null device");
+ }catch(IllegalArgumentException ex) {
+ // expected
+ }
+ try{
+ CLContext.create((CLPlatform)null, (CLDevice.Type)null);
+ fail("create with null CLDevice.Type");
+ }catch(IllegalArgumentException ex) {
+ // expected
+ }
+
}
@Test