So I'm making a Real Time Raytracer and as a result, I've enter the realm of OpenCL for the first time ever... which means I'm pretty terrible at it, at the moment.

I've been attempting to implement a Uniform Grid to store my objects and then traverse the grid in the OpenCL kernel to find what to check collisions with.
My grid is represented as a 4D array stored as a 1D array (since OpenCL only supports 1D arrays) where the 4th dimension is the actual objects in that particular cell of the grid.

I actually have grid traversal working! I can obtain a list of all elements that contain objects that the ray has passed through, via form of the DDA Algorithm seen in the paper "A Fast Voxel Traversal Algorithm".
So I have a list of the elements in the grid I require. Each element contains a number which is the ID of the object.
So I now need to pass that in to my array of objects to get out the object the ID corresponds to, like so:

Code :
object = objectList[uniformGrid[element]];

Where 'element' is the element with a confirmed object that the ray is near, 'uniformGrid' is the 4D/1D array and 'objectList' is the list of objects.
Problem is, it seems that due to the inlining nature of OpenCL, trying to get an element from one array using an arbitrary element from another array... doesn't work!
The kernel building gets stuck for about 5 minutes and eventually throws a bad_alloc error. No error is ever returned from the actual build function since the program terminates before it can.

So my questions are: Are there ways around this? Or better yet, is their a more 'common' way of implementing a Uniform Grid traversal than this?

I can't find any open source systems that use this method, so if anyone has anything like that, it'd be a great help!

Thanks! <3