f13rce Posted August 13, 2014 Share Posted August 13, 2014 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: 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 More sharing options...
Josh Posted August 20, 2014 Share Posted August 20, 2014 I need a map to test, please. If FindPath cannot find a path, it just returns NULL. My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted August 20, 2014 Share Posted August 20, 2014 Can you provide a code example that will produce this error? My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted August 21, 2014 Share Posted August 21, 2014 I believe we have this worked out. Please tell me if that turns out not to be the case. My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts