Fix #122756: Crash when node outputs an empty GVolumeGrid

`GVolumeGrid` and `VolumeGrid<T>` are basically pointer wrappers.
Assigning a nullptr is possible and allowed by code, but node socket
code doesn't currently check if a grid pointer is null before accessing
it.

Disallow null grid pointers in socket values. Asserts are added for this
purpose. The Points-to-SDF node checks the grid value before writing to
output.

Pull Request: https://projects.blender.org/blender/blender/pulls/122996
This commit is contained in:
Lukas Tönne
2024-06-10 13:55:15 +02:00
parent 5c2e3f2cac
commit ddd079b54f
2 changed files with 8 additions and 1 deletions

View File

@@ -93,6 +93,7 @@ template<typename T> T SocketValueVariant::extract()
else if constexpr (std::is_same_v<T, GVolumeGrid>) {
switch (kind_) {
case Kind::Grid: {
BLI_assert(value_);
return std::move(value_.get<GVolumeGrid>());
}
case Kind::Single:
@@ -152,6 +153,7 @@ template<typename T> void SocketValueVariant::store_impl(T value)
}
#ifdef WITH_OPENVDB
else if constexpr (std::is_same_v<T, GVolumeGrid>) {
BLI_assert(value);
const VolumeGridType volume_grid_type = value->grid_type();
const std::optional<eNodeSocketDatatype> new_socket_type = grid_type_to_socket_type(
volume_grid_type);
@@ -161,6 +163,7 @@ template<typename T> void SocketValueVariant::store_impl(T value)
value_.emplace<GVolumeGrid>(std::move(value));
}
else if constexpr (is_VolumeGrid_v<T>) {
BLI_assert(value);
this->store_impl<GVolumeGrid>(std::move(value));
}
#endif

View File

@@ -93,7 +93,11 @@ static void node_geo_exec(GeoNodeExecParams params)
bke::VolumeGrid<float> grid = points_to_grid(params.extract_input<GeometrySet>("Points"),
params.extract_input<Field<float>>("Radius"),
params.extract_input<float>("Voxel Size"));
params.set_output("SDF Grid", std::move(grid));
if (grid) {
params.set_output("SDF Grid", std::move(grid));
}
params.set_default_remaining_outputs();
#else
node_geo_exec_with_missing_openvdb(params);
#endif