From 9aade6bd610ef91d4e82e0f0cb64c77f1edbfc21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20T=C3=B6nne?= Date: Fri, 26 Sep 2025 15:26:22 +0200 Subject: [PATCH] Fix #145762: Ensure a valid background value before pruning SDF grid OpenVDB will throw an exception when trying to prune a SDF/Level-Set grid with a negative background value. The geometry nodes in this case are constructing a nominal SDF grid from a generic "density" volume cube. The negative background value results from processing the background value the same way as all other grid values in the new field+grid math feature (`blender::nodes::process_background`). Since any grid can be constructed with a negative background value we have to check and correct this before calling the OpenVDB prune function. Pull Request: https://projects.blender.org/blender/blender/pulls/146837 --- source/blender/geometry/intern/volume_grid_resample.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/blender/geometry/intern/volume_grid_resample.cc b/source/blender/geometry/intern/volume_grid_resample.cc index dbcb33026c0..fd92ebddb87 100644 --- a/source/blender/geometry/intern/volume_grid_resample.cc +++ b/source/blender/geometry/intern/volume_grid_resample.cc @@ -28,6 +28,11 @@ openvdb::FloatGrid &resample_sdf_grid_if_necessary(bke::VolumeGrid &volum /* TODO: Using #doResampleToMatch when the transform is affine and non-scaled may be faster. */ openvdb::tools::resampleToMatch(grid, *storage); + /* Ensure valid background value for level set grids, otherwise pruning will throw an exception. + */ + if (storage->background() < 0.0f) { + storage->tree().root().setBackground(0.0f, true); + } openvdb::tools::pruneLevelSet(storage->tree()); return *storage;