cl::vector vs std::vector with cl::Events

Hi!
I am trying to figure out why this code generates an error (Unhandled exception, Access violation reading location…) when releasing the events if __NO_STD_VECTOR is defined, i.e. using the built in more simple vector class in OpenCL, but works perfectly fine using std::vector. I’ve been scratching my head bout this issue for quite some time now. Its like the destructor of cl::Event is called twice, once in destructor of the vector and once when leaving the scope of main. But it feels like this isn’t the intended behaviour considering they are vectors of cl::Event everywhere in the c++ API of OpenCL, which in turn makes me believe I’ve overseen an obvious error in the code. Still it works with std::vector and not cl::vector… Any help is greatly appreciated!

(note this is a simpler test case that reproduces the error)


#define __NO_STD_STRING 
#define __NO_STD_VECTOR

#include <CL/cl.hpp>

const __int64 FILE_LENGTH = 1024*128;
#define NUM_WRITES 2

int main()
{
	
	cl::CommandQueue commandQueues;
	cl::Program program;
	cl::Context context;
	cl_device_id device_id; 
	VECTOR_CLASS<cl::Platform> platforms;
	VECTOR_CLASS<cl::Device> devices;

	cl_int error;
	error = cl::Platform::get(&platforms);

	if(error !=CL_SUCCESS)//handle error better
	{
		return false;
	}

	cl_device_type type = CL_DEVICE_TYPE_GPU;
#ifdef ENCODE_CPU
	type = CL_DEVICE_TYPE_CPU;
#endif

	error = platforms[0].getDevices (type, &devices);
	if(error != CL_SUCCESS) //handle error better
	{
		return false; 
	}

	context =  cl::Context(devices);

	cl::CommandQueue queue = cl::CommandQueue(context, devices[0]);


	VECTOR_CLASS<cl::Event> m_Events;
	cl::Buffer destinationbuffer[NUM_WRITES];
	int n = 0;
	for(int i = 0;i<NUM_WRITES;i++)
	{
		destinationbuffer[i] = cl::Buffer(context,CL_MEM_ALLOC_HOST_PTR|CL_MEM_READ_ONLY,FILE_LENGTH,0,&error);
		if(error != CL_SUCCESS) //handle error better
		{
			printf("error");
		}
		m_Events.push_back(cl::Event());
		error = queue.enqueueFillBuffer<int>(destinationbuffer[i],n,0,FILE_LENGTH,0,&m_Events[i]);
		if(error != CL_SUCCESS) //handle error better
		{
			printf("error");
		}
	}
	cl::WaitForEvents(m_Events);
	m_Events.clear();
	return 0;
}

(removing m_Events.clear() at the end doesn’t change anything)

I’ve been requested to not use std::vector or std::string, so going with what works is not really an option.

The error occurs in both intel and amd sdk of opencl. I am using opencl 1.2.