Skip to content

Commit

Permalink
UPBGE: Fix duplication of navigation mesh objects.
Browse files Browse the repository at this point in the history
The duplication of navigation mesh was processing a regeneration of the mesh
and a registration to the scene in the function BuildNavMesh. But the caller
(ProcessReplica) is on an object without a scene graph node and so an access
to its scene, this mean that the try to register the nav mesh in the scene
obstacle simulation failed in BuildNavMesh because the scene is unreachable.

To fix this issue the management of obstacle simulation for nav mesh and
obstacles is fully moved into KX_Scene::AddNodeReplicaObject after the new
object ensure a scene graph node.

Fix issue #926.
  • Loading branch information
panzergame committed Nov 8, 2018
1 parent d138c81 commit b387a7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 1 addition & 5 deletions source/gameengine/Ketsji/KX_NavMeshObject.cpp
Expand Up @@ -119,11 +119,6 @@ void KX_NavMeshObject::ProcessReplica()
{
KX_GameObject::ProcessReplica();
m_navMesh = nullptr;

if (!BuildNavMesh()) {
CM_FunctionError("unable to build navigation mesh");
return;
}
}

int KX_NavMeshObject::GetGameObjectType() const
Expand Down Expand Up @@ -383,6 +378,7 @@ bool KX_NavMeshObject::BuildNavMesh()
float cs = 0.2f;

if (!nverts || !npolys) {
CM_FunctionError("unable to build navigation mesh");
if (vertices) {
delete[] vertices;
}
Expand Down
5 changes: 5 additions & 0 deletions source/gameengine/Ketsji/KX_Scene.cpp
Expand Up @@ -54,6 +54,7 @@
#include "SCA_ActuatorEventManager.h"
#include "SCA_BasicEventManager.h"
#include "KX_Camera.h"
#include "KX_NavMeshObject.h"
#include "SCA_JoystickManager.h"
#include "KX_PyMath.h"
#include "KX_Mesh.h"
Expand Down Expand Up @@ -497,6 +498,10 @@ KX_GameObject *KX_Scene::AddNodeReplicaObject(SG_Node *node, KX_GameObject *game
if (m_obstacleSimulation && gameobj->GetBlenderObject()->gameflag & OB_HASOBSTACLE) {
m_obstacleSimulation->AddObstacleForObj(newobj);
}
// Reconstruct nav mesh.
if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_NAVMESH) {
static_cast<KX_NavMeshObject *>(gameobj)->BuildNavMesh();
}

// Register object for component update.
if (gameobj->GetComponents()) {
Expand Down

0 comments on commit b387a7f

Please sign in to comment.