diff --git a/vtkm/cont/internal/Buffer.cxx b/vtkm/cont/internal/Buffer.cxx index bc0a8fdc4..4110af8c8 100644 --- a/vtkm/cont/internal/Buffer.cxx +++ b/vtkm/cont/internal/Buffer.cxx @@ -1164,9 +1164,14 @@ void Serialization::save(BinaryBuffer& bb, vtkm::BufferSizeType size = obj.GetNumberOfBytes(); vtkmdiy::save(bb, size); - vtkm::cont::Token token; - const vtkm::UInt8* data = reinterpret_cast(obj.ReadPointerHost(token)); - vtkmdiy::save(bb, data, static_cast(size)); + if (size) + { + // NOTE: If size == 0, obj.ReadPointerHost will be a nullptr, and saving that via + // vtkmdiy causes test failure on osheim + vtkm::cont::Token token; + const vtkm::UInt8* data = reinterpret_cast(obj.ReadPointerHost(token)); + vtkmdiy::save(bb, data, static_cast(size)); + } } void Serialization::load(BinaryBuffer& bb, @@ -1177,8 +1182,11 @@ void Serialization::load(BinaryBuffer& bb, vtkm::cont::Token token; obj.SetNumberOfBytes(size, vtkm::CopyFlag::Off, token); - vtkm::UInt8* data = reinterpret_cast(obj.WritePointerHost(token)); - vtkmdiy::load(bb, data, static_cast(size)); + if (size) + { + vtkm::UInt8* data = reinterpret_cast(obj.WritePointerHost(token)); + vtkmdiy::load(bb, data, static_cast(size)); + } } } // namespace diy diff --git a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx index f790c38d5..93afbf170 100644 --- a/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx +++ b/vtkm/cont/testing/UnitTestSerializationArrayHandle.cxx @@ -150,6 +150,19 @@ struct TestArrayHandleBasic } }; +struct TestArrayHandleBasicEmpty +{ + template + void operator()(T) const + { + vtkm::cont::ArrayHandle array; + array.Allocate(0); + RunTest(array); + RunTest(MakeTestUnknownArrayHandle(array)); + RunTest(MakeTestUncertainArrayHandle(array)); + } +}; + struct TestArrayHandleSOA { template @@ -372,6 +385,12 @@ void TestArrayHandleSerialization() vtkm::testing::Testing::TryTypes( TestArrayHandleBasic(), vtkm::List()); + std::cout << "Testing empty ArrayHandleBasic\n"; + vtkm::testing::Testing::TryTypes(TestArrayHandleBasicEmpty(), TestTypesList()); + vtkm::testing::Testing::TryTypes( + TestArrayHandleBasicEmpty(), + vtkm::List()); + std::cout << "Testing ArrayHandleSOA\n"; vtkm::testing::Testing::TryTypes(TestArrayHandleSOA(), TestTypesListVec());