             pos += elem_step)
         {
             float inv_z = 1.0f / (v_z + Rcurr_inv.data[2].z * z_scaled);
+            if (inv_z < 0)
+                continue;
 
             // project to current cam
             int2 coo =

  namespace device
  {
    __global__ void
    scaleDepth (const PtrStepSz<ushort> depth, PtrStepSz<float> scaled, const Intr intr)
    {
      int x = threadIdx.x + blockIdx.x * blockDim.x;
      int y = threadIdx.y + blockIdx.y * blockDim.y;

           pos += elem_step)
      {
        float inv_z = 1.0f / (v_z + Rcurr_inv.data[2].z * z_scaled);
        if (inv_z < 0)
            continue;

        // project to current cam
        int2 coo =
