Skip to content

Commit

Permalink
-Set/get-area fix: Use instanceId instead of 0 to prevent crashes whe…
Browse files Browse the repository at this point in the history
…n used in instances.
  • Loading branch information
mostlikely4r committed Oct 14, 2024
1 parent 122fc91 commit 3f0a4e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/game/MotionGenerators/PathFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ PathFinder::PathFinder(const Unit* owner, bool ignoreNormalization) :
m_cachedPoints(m_pointPathLimit * VERTEX_SIZE), m_pathPolyRefs(m_pointPathLimit), m_polyLength(0),
m_smoothPathPolyRefs(m_pointPathLimit), m_sourceUnit(owner), m_navMesh(nullptr), m_navMeshQuery(nullptr),
m_defaultMapId(m_sourceUnit->GetMapId()), m_ignoreNormalization(ignoreNormalization)
#ifdef ENABLE_PLAYERBOTS
, m_defaultInstanceId(m_sourceUnit->GetInstanceId())
#endif
{
DEBUG_FILTER_LOG(LOG_FILTER_PATHFINDING, "++ PathFinder::PathInfo for %u \n", m_sourceUnit->GetGUIDLow());

Expand All @@ -54,15 +57,15 @@ PathFinder::PathFinder(const Unit* owner, bool ignoreNormalization) :
PathFinder::PathFinder() :
m_polyLength(0), m_type(PATHFIND_BLANK),
m_useStraightPath(false), m_forceDestination(false), m_straightLine(false), m_pointPathLimit(MAX_POINT_PATH_LENGTH), // TODO: Fix legitimate long paths
m_sourceUnit(nullptr), m_navMesh(nullptr), m_navMeshQuery(nullptr), m_cachedPoints(m_pointPathLimit* VERTEX_SIZE), m_pathPolyRefs(m_pointPathLimit), m_smoothPathPolyRefs(m_pointPathLimit), m_defaultMapId(0)
m_sourceUnit(nullptr), m_navMesh(nullptr), m_navMeshQuery(nullptr), m_cachedPoints(m_pointPathLimit* VERTEX_SIZE), m_pathPolyRefs(m_pointPathLimit), m_smoothPathPolyRefs(m_pointPathLimit), m_defaultMapId(0), m_defaultInstanceId(0)
{

}

PathFinder::PathFinder(uint32 mapId, uint32 instanceId) :
m_polyLength(0), m_type(PATHFIND_BLANK),
m_useStraightPath(false), m_forceDestination(false), m_straightLine(false), m_pointPathLimit(MAX_POINT_PATH_LENGTH), // TODO: Fix legitimate long paths
m_sourceUnit(nullptr), m_navMesh(nullptr), m_navMeshQuery(nullptr), m_cachedPoints(m_pointPathLimit* VERTEX_SIZE), m_pathPolyRefs(m_pointPathLimit), m_smoothPathPolyRefs(m_pointPathLimit), m_defaultMapId(mapId)
m_sourceUnit(nullptr), m_navMesh(nullptr), m_navMeshQuery(nullptr), m_cachedPoints(m_pointPathLimit* VERTEX_SIZE), m_pathPolyRefs(m_pointPathLimit), m_smoothPathPolyRefs(m_pointPathLimit), m_defaultMapId(mapId), m_defaultInstanceId(instanceId)
{
MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();
m_defaultNavMeshQuery = mmap->GetNavMeshQuery(mapId, instanceId);
Expand Down Expand Up @@ -175,7 +178,7 @@ void PathFinder::setArea(uint32 mapId, float x, float y, float z, uint32 area, f

MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();

dtNavMeshQuery const* query = mmap->GetNavMeshQuery(mapId, 0);
dtNavMeshQuery const* query = mmap->GetNavMeshQuery(mapId, m_defaultInstanceId);
dtNavMesh const* cnavMesh = mmap->GetNavMesh(mapId);
dtNavMesh* navMesh = const_cast<dtNavMesh*> (cnavMesh);
dtQueryFilter m_filter;
Expand Down Expand Up @@ -231,7 +234,7 @@ uint32 PathFinder::getArea(uint32 mapId, float x, float y, float z)

MMAP::MMapManager* mmap = MMAP::MMapFactory::createOrGetMMapManager();

dtNavMeshQuery const* query = mmap->GetNavMeshQuery(mapId, 0);
dtNavMeshQuery const* query = mmap->GetNavMeshQuery(mapId, m_defaultInstanceId);
dtNavMesh const* cnavMesh = mmap->GetNavMesh(mapId);
dtNavMesh* navMesh = const_cast<dtNavMesh*> (cnavMesh);
dtQueryFilter m_filter;
Expand Down
3 changes: 3 additions & 0 deletions src/game/MotionGenerators/PathFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ class PathFinder

const dtNavMeshQuery* m_defaultNavMeshQuery; // the nav mesh query used to find the path
uint32 m_defaultMapId;
#ifdef ENABLE_PLAYERBOTS
uint32 m_defaultInstanceId;
#endif

bool m_ignoreNormalization;

Expand Down

0 comments on commit 3f0a4e1

Please sign in to comment.