From b387a7f3d1e42a49bac509766438c43c64ab312b Mon Sep 17 00:00:00 2001 From: tristan Date: Thu, 8 Nov 2018 19:38:07 +0100 Subject: [PATCH] UPBGE: Fix duplication of navigation mesh objects. 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. --- source/gameengine/Ketsji/KX_NavMeshObject.cpp | 6 +----- source/gameengine/Ketsji/KX_Scene.cpp | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/gameengine/Ketsji/KX_NavMeshObject.cpp b/source/gameengine/Ketsji/KX_NavMeshObject.cpp index 62742ba56a79..ee860cc2f2ad 100644 --- a/source/gameengine/Ketsji/KX_NavMeshObject.cpp +++ b/source/gameengine/Ketsji/KX_NavMeshObject.cpp @@ -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 @@ -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; } diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 17fc7c735476..a1391200b393 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -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" @@ -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(gameobj)->BuildNavMesh(); + } // Register object for component update. if (gameobj->GetComponents()) {