Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out-of-bounds array access in AMR sampler #26

Open
szellmann opened this issue May 28, 2024 · 0 comments
Open

Out-of-bounds array access in AMR sampler #26

szellmann opened this issue May 28, 2024 · 0 comments

Comments

@szellmann
Copy link

I'm experiencing out-of-bounds array accesses with the AMR sampler. I tracked the issue down to this access into the brick voxel list: https://github.com/RenderKit/openvkl/blob/master/openvkl/devices/cpu/volume/amr/CellRef.ispc#L90

Here's some local variable info for a case where this fails (on the 4th SIMD lane):

brickSize: [((512)),((512)),((512)),512] // that's brick->dim.x*brick->dim.y*brick->dim.z
f_bc.x: [((3.000000)),((2.000000)),((2.000000)),2.000000]
f_bc.y: [((7.000000)),((7.000000)),((7.000000)),8.000000]
f_bc.z: [((8.000000)),((7.000000)),((7.000000)),7.000000]
f_dims.x: 8.000000
f_dims.y: 8.000000
f_dims.z: 8.000000
relBrickPos.x: [((0.388464)),((0.359136)),((0.364288)),0.343571]
relBrickPos.y: [((0.985767)),((0.999565)),((0.991043)),1.000000]
relBrickPos.z: [((1.063786)),((0.960573)),((0.995874)),0.915741]
/Users/stefan/openvkl/openvkl/include/../common/Data.ih:128:101: Assertion failed: index32 >= 0 && index32 < data.numItems

This fails as const vec3f f_bc = floor(relBrickPos * brick->f_dims); does not round down if relBrickPos is exactly 1.0.

Not sure what the best fix is. This works for me:

    vec3f relBrickPos
          = (worldSpacePos - brick->bounds.lower) * brick->bounds_scale;
        relBrickPos.x = clamp(relBrickPos.x, 0.f, 0.9999f);
        relBrickPos.y = clamp(relBrickPos.y, 0.f, 0.9999f);
        relBrickPos.z = clamp(relBrickPos.z, 0.f, 0.9999f);

or another solution would be clamping f_bc to the interval [0.f,f_dims-1.f].

(I can't trigger it there, but the code here might have the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant