diff --git a/apps/navmeshtool/worldspacedata.cpp b/apps/navmeshtool/worldspacedata.cpp index 19a85d60c6..9712b80b6f 100644 --- a/apps/navmeshtool/worldspacedata.cpp +++ b/apps/navmeshtool/worldspacedata.cpp @@ -3,11 +3,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -17,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -29,8 +32,8 @@ #include #include -#include #include +#include #include #include #include @@ -219,6 +222,16 @@ namespace NavMeshTool const std::vector data = serialize(value); getRawStderr().write(reinterpret_cast(data.data()), static_cast(data.size())); } + + std::string makeAddObjectErrorMessage( + ObjectId objectId, DetourNavigator::AreaType areaType, const CollisionShape& shape) + { + std::ostringstream stream; + stream << "Failed to add object to recast mesh objectId=" << objectId.value() << " areaType=" << areaType + << " fileName=" << shape.getInstance()->mFileName + << " fileHash=" << Misc::StringUtils::toHex(shape.getInstance()->mFileHash); + return stream.str(); + } } WorldspaceNavMeshInput::WorldspaceNavMeshInput( @@ -318,14 +331,19 @@ namespace NavMeshTool const CollisionShape shape(object.getShapeInstance(), *object.getCollisionObject().getCollisionShape(), object.getObjectTransform()); - navMeshInput.mTileCachedRecastMeshManager.addObject( - objectId, shape, transform, DetourNavigator::AreaType_ground, guard.get()); + if (!navMeshInput.mTileCachedRecastMeshManager.addObject( + objectId, shape, transform, DetourNavigator::AreaType_ground, guard.get())) + throw std::logic_error( + makeAddObjectErrorMessage(objectId, DetourNavigator::AreaType_ground, shape)); if (const btCollisionShape* avoid = object.getShapeInstance()->mAvoidCollisionShape.get()) { + const ObjectId avoidObjectId(++objectsCounter); const CollisionShape avoidShape(object.getShapeInstance(), *avoid, object.getObjectTransform()); - navMeshInput.mTileCachedRecastMeshManager.addObject( - objectId, avoidShape, transform, DetourNavigator::AreaType_null, guard.get()); + if (!navMeshInput.mTileCachedRecastMeshManager.addObject( + avoidObjectId, avoidShape, transform, DetourNavigator::AreaType_null, guard.get())) + throw std::logic_error( + makeAddObjectErrorMessage(avoidObjectId, DetourNavigator::AreaType_null, avoidShape)); } data.mObjects.emplace_back(std::move(object));