From 657fdface666c7f9d961aecef0112cf47cf8a7a4 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Fri, 7 Jan 2022 00:19:41 -0700 Subject: [PATCH] Fix serialization of possibly empty SparsityPattern objects. --- include/deal.II/lac/sparsity_pattern.h | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/include/deal.II/lac/sparsity_pattern.h b/include/deal.II/lac/sparsity_pattern.h index 011acc1acb..0306c6ac89 100644 --- a/include/deal.II/lac/sparsity_pattern.h +++ b/include/deal.II/lac/sparsity_pattern.h @@ -1588,8 +1588,15 @@ SparsityPatternBase::save(Archive &ar, const unsigned int) const ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed; - ar &boost::serialization::make_array(rowstart.get(), max_dim + 1); - ar &boost::serialization::make_array(colnums.get(), max_vec_len); + if (max_dim != 0) + ar &boost::serialization::make_array(rowstart.get(), max_dim + 1); + else + Assert(rowstart.get() == nullptr, ExcInternalError()); + + if (max_vec_len != 0) + ar &boost::serialization::make_array(colnums.get(), max_vec_len); + else + Assert(colnums.get() == nullptr, ExcInternalError()); } @@ -1603,11 +1610,21 @@ SparsityPatternBase::load(Archive &ar, const unsigned int) ar &max_dim &rows &cols &max_vec_len &max_row_length &compressed; - rowstart = std::make_unique(max_dim + 1); - colnums = std::make_unique(max_vec_len); + if (max_dim != 0) + { + rowstart = std::make_unique(max_dim + 1); + ar &boost::serialization::make_array(rowstart.get(), max_dim + 1); + } + else + rowstart.reset(); - ar &boost::serialization::make_array(rowstart.get(), max_dim + 1); - ar &boost::serialization::make_array(colnums.get(), max_vec_len); + if (max_vec_len != 0) + { + colnums = std::make_unique(max_vec_len); + ar &boost::serialization::make_array(colnums.get(), max_vec_len); + } + else + colnums.reset(); } -- 2.39.5