From e98f93a079c2cfea7b5478e2cb2934874e0b88e0 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 5 Apr 2020 13:41:14 +0100 Subject: Only store IDs across ticks --- src/NetherPortalScanner.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/NetherPortalScanner.cpp') diff --git a/src/NetherPortalScanner.cpp b/src/NetherPortalScanner.cpp index 8de0a6dcc..386da61fb 100644 --- a/src/NetherPortalScanner.cpp +++ b/src/NetherPortalScanner.cpp @@ -17,8 +17,9 @@ const double cNetherPortalScanner::AcrossOffset = 0.5; -cNetherPortalScanner::cNetherPortalScanner(cEntity * a_MovingEntity, cWorld * a_DestinationWorld, Vector3d a_DestPosition, int a_MaxY) : - m_Entity(a_MovingEntity), +cNetherPortalScanner::cNetherPortalScanner(cEntity & a_MovingEntity, cWorld * a_DestinationWorld, Vector3d a_DestPosition, int a_MaxY) : + m_EntityID(a_MovingEntity.GetUniqueID()), + m_SourceWorld(*a_MovingEntity.GetWorld()), m_World(a_DestinationWorld), m_FoundPortal(false), m_BuildPlatform(true), @@ -296,8 +297,18 @@ void cNetherPortalScanner::OnDisabled(void) Position.z += OutOffset; } - FLOGD("Placing player at {0}", Position); - m_Entity->MoveToWorld(m_World, Position, true, false); + // Lookup our warping entity by ID + // Necessary as they may have been destroyed in the meantime (#4582) + m_SourceWorld.DoWithEntityByID( + m_EntityID, + [this, &Position](cEntity & a_Entity) + { + FLOGD("Placing player at {0}", Position); + a_Entity.MoveToWorld(m_World, Position, true, false); + return true; + } + ); + delete this; } -- cgit v1.2.3