From 6ca42ce154439b8c2f7f76ce4300ae08678f223a Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Fri, 21 Jan 2011 23:45:39 +0100 Subject: missing buffer rewind in source upload code (bug id: #458). --- src/com/jogamp/opencl/CLProgram.java | 13 +++++++++---- test/com/jogamp/opencl/LowLevelBindingTest.java | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/com/jogamp/opencl/CLProgram.java b/src/com/jogamp/opencl/CLProgram.java index 548997e8..e74ebed3 100644 --- a/src/com/jogamp/opencl/CLProgram.java +++ b/src/com/jogamp/opencl/CLProgram.java @@ -73,14 +73,19 @@ public class CLProgram extends CLObject implements CLResource { static CLProgram create(CLContext context, String src) { - IntBuffer status = newDirectByteBuffer(4).asIntBuffer(); + IntBuffer status = newDirectIntBuffer(1); + + PointerBuffer length = (PointerBuffer)PointerBuffer.allocateDirect(1).put(0, src.length()); + String[] srcArray = new String[] {src}; + // Create the program - long id = context.cl.clCreateProgramWithSource(context.ID, 1, new String[] {src}, - (PointerBuffer)PointerBuffer.allocateDirect(1).put(src.length()), status); + long id = context.cl.clCreateProgramWithSource(context.ID, 1, srcArray, length, status); int err = status.get(); if(err != CL_SUCCESS) { - throw newException(err, "can not create program with source on "+context); + // don't remove: locks the reference (length and srcArray) + length.rewind(); + throw newException(err, "can not create program with source (length="+srcArray[0].length()+") on "+context); } return new CLProgram(context, id); diff --git a/test/com/jogamp/opencl/LowLevelBindingTest.java b/test/com/jogamp/opencl/LowLevelBindingTest.java index b531dd94..524743b2 100644 --- a/test/com/jogamp/opencl/LowLevelBindingTest.java +++ b/test/com/jogamp/opencl/LowLevelBindingTest.java @@ -279,7 +279,7 @@ public class LowLevelBindingTest { // Create the program - PointerBuffer lengths = (PointerBuffer)PointerBuffer.allocateDirect(1).put(programSource.length()); + PointerBuffer lengths = (PointerBuffer)PointerBuffer.allocateDirect(1).put(programSource.length()).rewind(); final long program = cl.clCreateProgramWithSource(context, 1, new String[] {programSource}, lengths, intBuffer); out.println("program id: "+program); checkError("on clCreateProgramWithSource", intBuffer.get(0)); -- cgit v1.2.3