From d9c5a5d1a9bd86d59d934895d7efe0e24158550e Mon Sep 17 00:00:00 2001
From: mattijs <mattijs>
Date: Thu, 1 Feb 2024 13:14:09 +0000
Subject: [PATCH] BUG: mapped: register to current, not other mesh. See #2723

---
 .../mappedPatches/mappedPolyPatch/mappedPatchBaseI.H       | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H
index b2ebe51e9ff..bdb2732b34d 100644
--- a/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H
+++ b/src/meshTools/mappedPatches/mappedPolyPatch/mappedPatchBaseI.H
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2015 OpenFOAM Foundation
-    Copyright (C) 2020-2021 OpenCFD Ltd.
+    Copyright (C) 2020-2021,2024 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -201,7 +201,10 @@ Foam::mappedPatchBase::updateSampleMeshTime() const
 {
     if (!updateSampleMeshTimePtr_)
     {
-        const auto& mesh = sampleMesh();
+        // Note: explicitly register on our mesh instead of sampleMesh
+        // since otherwise the destructor might give problems since sampleMesh
+        // might have already been taken down before.
+        const auto& mesh = patch_.boundaryMesh().mesh();
 
         updateSampleMeshTimePtr_.reset
         (
-- 
GitLab