diff --git a/src/axom/core/memory_management.hpp b/src/axom/core/memory_management.hpp index 3475694e6a..92f046c990 100644 --- a/src/axom/core/memory_management.hpp +++ b/src/axom/core/memory_management.hpp @@ -235,7 +235,28 @@ inline T* reallocate(T* pointer, std::size_t n, int allocID) noexcept } else { - pointer = static_cast(rm.reallocate(pointer, numbytes)); + constexpr bool workAround = true; + if(workAround) + { + /* + This work-around addresses issue #1287 and PR #1271. + The reproducer is the immediate_ug_reserve test in file + axom/src/axom/quest/test/quest_initialize.cpp. This + work-around doesn't address the actual cause of the problem, + something we should try to identify and fix. + */ + auto oldPointer = pointer; + auto foundAllocator = rm.getAllocator(pointer); + auto oldSize = foundAllocator.getSize(pointer); + pointer = static_cast(foundAllocator.allocate(numbytes)); + auto copysize = std::min(oldSize, numbytes); + axom::copy(pointer, oldPointer, copysize); + axom::deallocate(oldPointer); + } + else + { + pointer = static_cast(rm.reallocate(pointer, numbytes)); + } } #else diff --git a/src/axom/mint/tests/mint_mesh.cpp b/src/axom/mint/tests/mint_mesh.cpp index cc707aed21..36adb1080d 100644 --- a/src/axom/mint/tests/mint_mesh.cpp +++ b/src/axom/mint/tests/mint_mesh.cpp @@ -725,6 +725,18 @@ TEST(mint_mesh, get_mixed_topology_unstructured_from_sidre) delete m; } +//------------------------------------------------------------------------------ +TEST(mint_mesh, immediate_ug_reserve) +{ + axom::sidre::DataStore objectDS; + axom::sidre::Group* meshGroup = objectDS.getRoot()->createGroup("myGroup"); + axom::mint::UnstructuredMesh contourMesh( + 2, + axom::mint::CellType::SEGMENT, + meshGroup); + contourMesh.reserveCells(10); // This may crash. +} + #endif /* AXOM_MINT_USE_SIDRE */ } /* namespace mint */ diff --git a/src/axom/quest/examples/quest_marching_cubes_example.cpp b/src/axom/quest/examples/quest_marching_cubes_example.cpp index f324660ecb..3e17fedfab 100644 --- a/src/axom/quest/examples/quest_marching_cubes_example.cpp +++ b/src/axom/quest/examples/quest_marching_cubes_example.cpp @@ -916,13 +916,12 @@ struct ContourTestBase AXOM_ANNOTATE_BEGIN("convert to mint mesh"); std::string sidreGroupName = "contour_mesh"; sidre::DataStore objectDS; - // While awaiting fix for PR #1271, don't use Sidre storage in contourMesh. auto* meshGroup = objectDS.getRoot()->createGroup(sidreGroupName); - AXOM_UNUSED_VAR(meshGroup); // variable is only referenced in debug configs axom::mint::UnstructuredMesh contourMesh( DIM, - DIM == 2 ? mint::CellType::SEGMENT : mint::CellType::TRIANGLE); + DIM == 2 ? mint::CellType::SEGMENT : mint::CellType::TRIANGLE, + meshGroup); axom::utilities::Timer extractTimer(false); extractTimer.start(); mc.populateContourMesh(contourMesh, m_parentCellIdField, m_domainIdField); diff --git a/src/axom/quest/tests/quest_initialize.cpp b/src/axom/quest/tests/quest_initialize.cpp index f8f2f6c67f..8e5194ba21 100644 --- a/src/axom/quest/tests/quest_initialize.cpp +++ b/src/axom/quest/tests/quest_initialize.cpp @@ -6,6 +6,9 @@ // Axom includes #include "axom/mint.hpp" #include "quest_test_utilities.hpp" +#if defined AXOM_USE_SIDRE + #include "axom/sidre.hpp" +#endif #include "axom/quest/interface/inout.hpp" #include "axom/quest/interface/signed_distance.hpp" @@ -72,6 +75,20 @@ TEST(quest_initialize, signed_distance_pointer_initialize) delete input_mesh; } +#if defined AXOM_USE_SIDRE +// Test immediately reserving space in UnstructuredMesh. +TEST(quest_initialize, immediate_ug_reserve) +{ + axom::sidre::DataStore objectDS; + axom::sidre::Group* meshGroup = objectDS.getRoot()->createGroup("myGroup"); + axom::mint::UnstructuredMesh contourMesh( + 2, + axom::mint::CellType::SEGMENT, + meshGroup); + contourMesh.reserveCells(10); // This may unexpectedly crash. +} +#endif + int main(int argc, char** argv) { #ifdef AXOM_USE_MPI