Skip to content

fix: image move constructor passes wrong stride unit to base constructor#119

Merged
david-tingdahl-nvidia merged 1 commit intonvidia-isaac:publicfrom
miwechner:fix-image-move-stride
Mar 6, 2026
Merged

fix: image move constructor passes wrong stride unit to base constructor#119
david-tingdahl-nvidia merged 1 commit intonvidia-isaac:publicfrom
miwechner:fix-image-move-stride

Conversation

@miwechner
Copy link
Contributor

@miwechner miwechner commented Feb 22, 2026

Closes #118

This debug assertion in Image could be hit:

__host__ __device__ static int strideFromBytesToElements(
const int stride_bytes) {
NVBLOX_DCHECK(stride_bytes % (sizeof(ElementType)) == 0,
"Stride must be a multiple of the element size in bytes");
return stride_bytes / (sizeof(ElementType));
}

, because for the constructor ImageBase::ImageBase(int rows, int cols, int stride_bytes, int num_elements_per_pixel, OtherElementType* data) the Image move constructor passed the stride in number of elements instead of number bytes.

The fix is straightforward: pass the strides in numbers of bytes instead of numbers of elements on that call.

@david-tingdahl-nvidia
Copy link
Contributor

Thanks for finding and fixing this bug. Could easily lead to some pretty confusing/weird errors. It hasn’t affected us much since we rarely use std::move with DepthImages, and when we do the image is (luckily) immediately resized, which recomputes the strides.

Could you please:

  • Update the commit message to briefly describe the fix (so readers don’t need to open the link), and
  • Fix the CI formatting error

Following this bug, we are also looking into extending the test suite for Image

Image move constructor passed the stride in number of elements, while ImageBase expects the stride in number of bytes.
This would cause an assert error in debug and potentially corrupt memory access.
@miwechner miwechner force-pushed the fix-image-move-stride branch from 1b915d6 to 567ab48 Compare February 26, 2026 18:52
@miwechner
Copy link
Contributor Author

miwechner commented Feb 26, 2026

Hi,

Thanks for the quick response. Good to hear that this was actually an important problem and I guess we were mostly lucky that moving images did not happen much. Without the debug assert, I would have never noticed.

Hope the updates on the commit message and the PR description are ok now, as well as the formatting.

Copy link
Contributor

@david-tingdahl-nvidia david-tingdahl-nvidia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@david-tingdahl-nvidia david-tingdahl-nvidia merged commit 3f42b21 into nvidia-isaac:public Mar 6, 2026
11 of 12 checks passed
@miwechner miwechner deleted the fix-image-move-stride branch March 6, 2026 09:55
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

Successfully merging this pull request may close these issues.

Debug assertation error: Image move constructor passes the stride in elements instead of bytes

2 participants