Index: source/simulation2/helpers/LongPathfinder.h =================================================================== --- source/simulation2/helpers/LongPathfinder.h +++ source/simulation2/helpers/LongPathfinder.h @@ -145,7 +145,7 @@ PriorityQueue open; // (there's no explicit closed list; it's encoded in PathfindTile) - PathfindTileGrid* tiles; + std::unique_ptr tiles; Grid* terrain; PathCost hBest; // heuristic of closest discovered tile to goal @@ -171,7 +171,6 @@ if (!m_DebugOverlay) return; - SAFE_DELETE(m_DebugGrid); delete m_DebugPath; m_DebugPath = new WaypointPath(); ComputePath(hierPath, x0, z0, goal, passClass, *m_DebugPath); @@ -225,7 +224,7 @@ // mutable as making these const would require a lot of boilerplate code // and they do not change the behavioural const-ness of the pathfinder. mutable LongOverlay* m_DebugOverlay; - mutable PathfindTileGrid* m_DebugGrid; + mutable std::unique_ptr m_DebugGrid; mutable u32 m_DebugSteps; mutable double m_DebugTime; mutable PathGoal m_DebugGoal; Index: source/simulation2/helpers/LongPathfinder.cpp =================================================================== --- source/simulation2/helpers/LongPathfinder.cpp +++ source/simulation2/helpers/LongPathfinder.cpp @@ -374,14 +374,13 @@ LongPathfinder::LongPathfinder() : m_UseJPSCache(false), m_Grid(NULL), m_GridSize(0), - m_DebugOverlay(NULL), m_DebugGrid(NULL), m_DebugPath(NULL) + m_DebugOverlay(NULL), m_DebugPath(NULL) { } LongPathfinder::~LongPathfinder() { SAFE_DELETE(m_DebugOverlay); - SAFE_DELETE(m_DebugGrid); SAFE_DELETE(m_DebugPath); } @@ -767,7 +766,7 @@ state.steps = 0; - state.tiles = new PathfindTileGrid(m_Grid->m_W, m_Grid->m_H); + state.tiles = std::unique_ptr(new PathfindTileGrid(m_Grid->m_W, m_Grid->m_H)); state.terrain = m_Grid; state.iBest = i0; @@ -901,8 +900,7 @@ ImprovePathWaypoints(path, passClass, origGoal.maxdist, x0, z0); // Save this grid for debug display - delete m_DebugGrid; - m_DebugGrid = state.tiles; + m_DebugGrid = std::move(state.tiles); m_DebugSteps = state.steps; m_DebugGoal = state.goal; }