From 2fc985f0cdc373cb3c78cc198e21dcc1ce5d961f Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Thu, 22 Apr 2010 04:07:14 +0200 Subject: CLContext should not throw NPE in create(...) if a device or device type is null. --- src/com/jogamp/opencl/CLContext.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/com') 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 -- cgit v1.2.3