Skip to content

Commit

Permalink
Fixed that voxelization failed in Intel OpenCL CPU runtime due to arr…
Browse files Browse the repository at this point in the history
…ay out-of-bounds access
  • Loading branch information
ProjectPhysX committed Apr 17, 2024
1 parent 1e5b86a commit d55be40
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2259,13 +2259,13 @@ string opencl_c_container() { return R( // ########################## begin of O
uint intersection = intersections%2u!=intersections_check%2u; // iterate through column, start with 0 regularly, start with 1 if forward and backward intersection count evenness differs (error correction)
const uint h0 = direction==0u ? xyz.x : direction==1u ? xyz.y : xyz.z;
const uint hmax = direction==0u ? (uint)clamp((int)x1-def_Ox, 0, (int)def_Nx) : direction==1u ? (uint)clamp((int)y1-def_Oy, 0, (int)def_Ny) : (uint)clamp((int)z1-def_Oz, 0, (int)def_Nz);
const uint hmesh = h0+(uint)distances[intersections-1u];
const uint hmesh = h0+(uint)distances[min(intersections-1u, 63u)]; // clamp (intersections-1u) to prevent array out-of-bounds access
for(uint h=h0; h<hmax; h++) {
while(intersection<intersections&&h>h0+(uint)distances[intersection]) {
while(intersection<intersections&&h>h0+(uint)distances[min(intersection, 63u)]) { // clamp intersection to prevent array out-of-bounds access
inside = !inside; // passed mesh intersection, so switch inside/outside state
intersection++;
}
inside &= (intersection<intersections&&h<hmesh); // point must be outside if there are no more ray-mesh intersections ahead (error correction)
inside = inside&&(intersection<intersections&&h<hmesh); // point must be outside if there are no more ray-mesh intersections ahead (error correction)
const ulong n = index((uint3)(direction==0u?h:xyz.x, direction==1u?h:xyz.y, direction==2u?h:xyz.z));
uchar flagsn = flags[n];
if(inside) {
Expand Down

0 comments on commit d55be40

Please sign in to comment.