AcademySoftwareFoundation / OpenShadingLanguage

Advanced shading language for production GI renderers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mismatch between sizeof(Partio::ParticleIndex), sizeof(size_t), sizeof(int)

StefanBruens opened this issue · comments

There is some assumption Partio uses size_t for its index type:

// RS::pointcloud_search takes size_t index array (because of the
// presumed use of Partio underneath), but OSL only has int, so we
// have to allocate and copy out. But, on architectures where int
// and size_t are the same, we can take a shortcut and let
// pointcloud_search fill in the array in place (assuming it's
// passed in the first place).

which is apparently wrong (for the last 12 years):
https://github.com/wdas/partio/blob/7cb3743c6e19c04ac049c05f8f81af2f24410ea3/src/lib/Partio.h#L55
typedef uint64_t ParticleIndex;

On 32 bit archs the compilation then fails due to:

static_assert (sizeof(size_t) == sizeof(Partio::ParticleIndex),
"Partio ParticleIndex should be the size of a size_t");
// FIXME -- if anybody cares about an architecture in which that is not
// the case, we can easily allocate local space to retrieve the indices,
// then copy them back to the caller's indices.

Wouldn't it be better change it to unsigned long* out_indices in RendererServices::pointcloud_search? (This may require a version bump for 64bit archs, but only if size_t != unsigned long. For 32bit archs, the current code does not work anyway). Dito for pointcloud_get.