Use of EnqueueMapBuffer

Jan 12, 2015 at 9:28 AM
Hi. I'm trying to use EnqueueMapBuffer so I won't have any copies of my objects. So, after I run my kernel I want to get the output using that. Here is a part of the code:
Event kernelRun = CLenvironment.kernel_createFade.EnqueueRun(CLenvironment.CommandQueue, CL_imageLeft, CL_imageRight, CL_output, CL_widths, CL_CopyAndPastPositions, nGlobalWorkSize, nLocalWorkSize);

Event e;
ErrorCode error;

InfoBuffer buf = Cl.EnqueueMapBuffer(CLenvironment.CommandQueue, CL_output, Bool.True, MapFlags.Read, (IntPtr)0, (IntPtr)(FadeArray.Length * sizeof(int)), 1, new Event[1] { kernelRun }, out e, out error);
So far so good. The CL_output is updated with new values calculated in the kernel function. But when I Unmaped it, it returns "InvalidValue" and I don't know why.
error=Cl.EnqueueUnmapObject(CLenvironment.CommandQueue, CL_output, buf, 1, new Event[1]{e}, out e);
Any thoughts?
Thanks