Jump to content

FindPath() crash


f13rce
 Share

Recommended Posts

I believe FindPath() is having a bug where it crashes whenever you try to navigate near an obstacle. It looks like it's failing to plot a path so it just crashes. You can't check it for NULL either.

 

It might have to do with the gap over here:

post-358-0-54753200-1407937597_thumb.jpg

 

How to recreate it:

Preparation:

Create a new scene

Create a large box as ground

Create a box as obstacle in the scene

(In C++) Create an object (let's say player) that uses FindPath() to navigate around.*

 

Recreating it:

Move close to the obstacle with the player (or just spawn the player near the obstacle)

Use FindPath() to move to the other side of the obstacle (preferably near the obstacle as well)

 

Video example:

(Skip to 3:27 to see a short version, everything before is how I prepared it)

 

*Code example of moving around:

void Unit::SetTargetPoint(Vec3 pos){

//Clear path before use
if (path != NULL)
path->points.clear();
waypoint = -1;

NavPath* p;
try{
printf("Finding path... plswork\n");
p = path->navmesh->FindPath(pivot->GetPosition(), pos);
}
catch (exception& e){
cout << "Exception: " << e.what() << endl;
printf("Path could not be made.\n");
return;
}

//If we can find a path
if (p != NULL){
path = p;
goTo->SetPosition(path->points.at(0).x, 1, path->points.at(0).z); //goTo is a pivot for calculating distance when moving; basically to see whether we're at our waypoint or not
finalGoTo->SetPosition(path->points.at(path->points.size()-1).x, 1, path->points.at(path->points.size()-1).z); //same at goTo, but for our final waypoint
//Look at our newest waypoint
pivot->Point(goTo, 3);
pivot->SetRotation(0, pivot->GetRotation().y, 0);
canMove = true;
}

//Could not find a path
else{
canMove = false;
waypoint = -1;
}

}

//Not really needed because we only need to plot a path, but maybe nice to have to make testing easier
void Unit::MoveToPoint(){
if (!canMove) return;
if (path->points.size() <= 0) return; //Just in case...
int pps = path->points.size(); //pps = Path Points Size

if (waypoint < pps-1){
pivot->Point(goTo, 3);
pivot->SetRotation(0, pivot->GetRotation().y, 0);
pivot->Move(0,0,GetSpeed()*Time::GetSpeed());
}

if (waypoint+1 < pps-1){
if (pivot->GetDistanceToEntity(goTo) < 0.65f){
waypoint++;
goTo->SetPosition(path->points.at(waypoint+1).x, 1, path->points.at(waypoint+1).z);
pivot->Point(goTo, 3);
pivot->SetRotation(0, pivot->GetRotation(false).y, 0);
}
}

}

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...