From ce927b059cccefe91b0617e6958691ff73efcc65 Mon Sep 17 00:00:00 2001 From: Matthias Holoch Date: Tue, 7 May 2024 11:45:29 +0200 Subject: [PATCH] fix crash when no color information exists in mesh source --- .../lvr2_hdf5_mesh_builder/HDF5MeshTool.cpp | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/tools/lvr2_hdf5_mesh_builder/HDF5MeshTool.cpp b/src/tools/lvr2_hdf5_mesh_builder/HDF5MeshTool.cpp index df8be5b31..7151084b3 100644 --- a/src/tools/lvr2_hdf5_mesh_builder/HDF5MeshTool.cpp +++ b/src/tools/lvr2_hdf5_mesh_builder/HDF5MeshTool.cpp @@ -257,6 +257,7 @@ int main( int argc, char ** argv ) DenseVertexMap colors; boost::optional> colorsOpt; ChannelOptional channel_opt; + bool colorsFoundInSource = false; if (readFromHdf5) { colorsOpt = hdf5In.getDenseAttributeMap>("vertex_colors"); @@ -265,10 +266,12 @@ int main( int argc, char ** argv ) { std::cout << timestamp << "Using existing vertex colors..." << std::endl; colors = *colorsOpt; + colorsFoundInSource = true; } else if (meshBuffer != nullptr && (channel_opt = meshBuffer->getChannel("vertex_colors")) && channel_opt && channel_opt.get().width() == 3 && channel_opt.get().numElements() == hem.numVertices()) { std::cout << timestamp << "Using existing colors from mesh buffer..." << std::endl; + colorsFoundInSource = true; auto &channel = channel_opt.get(); colors.reserve(channel.numElements()); @@ -279,16 +282,23 @@ int main( int argc, char ** argv ) } if (!colorsOpt || !writeToHdf5Input) { - std::cout << timestamp << "Adding vertex colors..." << std::endl; - bool addedVertexColors = hdf5.addDenseAttributeMap>( - hem, colors, "vertex_colors"); - if (addedVertexColors) + if (colorsFoundInSource) { - std::cout << timestamp << "successfully added vertex colors" << std::endl; - } - else + std::cout << timestamp << "Adding vertex colors found in source..." << std::endl; + bool addedVertexColors = hdf5.addDenseAttributeMap>( + hem, colors, "vertex_colors"); + if (addedVertexColors) + { + std::cout << timestamp << "successfully added vertex colors" << std::endl; + } + else + { + std::cout << timestamp << "could not add vertex colors!" << std::endl; + } + } + else { - std::cout << timestamp << "could not add vertex colors!" << std::endl; + std::cout << timestamp << "Skipping vertex colors: No colors found in input file." << std::endl; } } else