victorprad / InfiniTAM

A Framework for the Volumetric Integration of Depth Images
http://www.infinitam.org
Other
918 stars 351 forks source link

Have Segmentation fault when reading manually defined input voxel #97

Open billamiable opened 6 years ago

billamiable commented 6 years ago

Hi,

I want to use readVoxel function (see below) to read data of manually defined input voxel, like Vector3s loc(a,b,c);

_CPU_AND_GPU_CODE_ inline TVoxel readVoxel(const CONSTPTR(TVoxel) *voxelData, const CONSTPTR(ITMLib::ITMVoxelBlockHash::IndexData) *voxelIndex,
    const THREADPTR(Vector3i) & point, THREADPTR(int) &vmIndex, THREADPTR(ITMLib::ITMVoxelBlockHash::IndexCache) & cache)
{
    Vector3i blockPos;
    int linearIdx = pointToVoxelBlockPos(point, blockPos);

    if IS_EQUAL3(blockPos, cache.blockPos)
    {
        vmIndex = true;
        return voxelData[cache.blockPtr + linearIdx];
    }

    int hashIdx = hashIndex(blockPos);

    while (true)
    {
        ITMHashEntry hashEntry = voxelIndex[hashIdx];

        if (IS_EQUAL3(hashEntry.pos, blockPos) && hashEntry.ptr >= 0)
        {
            cache.blockPos = blockPos; cache.blockPtr = hashEntry.ptr * SDF_BLOCK_SIZE3;
            vmIndex = hashIdx + 1; // add 1 to support legacy true / false operations for isFound

            return voxelData[cache.blockPtr + linearIdx];
        }

        if (hashEntry.offset < 1) break;
        hashIdx = SDF_BUCKET_NUM + hashEntry.offset - 1;
    }

    vmIndex = false;
    return TVoxel();
}

However, when executing I have *** Failure: /path/spaint/build/bin/apps/spaintgui/spaintgui has crashed *** When I use Debug mode, the problem lies in this line: ITMHashEntry hashEntry = voxelIndex[hashIdx]; With the debug output

*** Program received signal SIGSEGV (Segmentation fault) ***
*** Exited on signal SIGSEGV ***

Any idea how to solve it? Thanks!

sgolodetz commented 6 years ago

Do you have a reason to expect that the hash table contains an entry for the relevant voxel? If the relevant entry doesn't exist, that's very likely why it's crashing.

billamiable commented 6 years ago

I first marked the scene (using spaint) and let it print out the voxel's 3d position, and then use it as the input for readVoxel function at the same frame (read offline data). I assume the hash table will contain in this way...

billamiable commented 6 years ago

Or are there any ways to get a voxel that must be contained by the hash table?

billamiable commented 6 years ago

I figured it out by using the raycast result. Thanks!