diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index 7b514ad..504df5b 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -687,6 +687,12 @@ public class RecastDemo : IRecastDemoChannel buildResult = soloNavMeshBuilder.Build(_sample.GetInputGeom(), settings); } + if (!buildResult.Success) + { + Logger.Error("failed to build"); + return; + } + _sample.Update(_sample.GetInputGeom(), buildResult.RecastBuilderResults, buildResult.NavMesh); _sample.SetChanged(false); settingsView.SetBuildTime((RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond); diff --git a/src/DotRecast.Recast.DemoTool/Builder/NavMeshBuildResult.cs b/src/DotRecast.Recast.DemoTool/Builder/NavMeshBuildResult.cs index f735b51..4b6b4d5 100644 --- a/src/DotRecast.Recast.DemoTool/Builder/NavMeshBuildResult.cs +++ b/src/DotRecast.Recast.DemoTool/Builder/NavMeshBuildResult.cs @@ -1,15 +1,25 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using DotRecast.Detour; namespace DotRecast.Recast.DemoTool.Builder { public class NavMeshBuildResult { + public readonly bool Success; public readonly IList RecastBuilderResults; public readonly DtNavMesh NavMesh; + public NavMeshBuildResult() + { + Success = false; + RecastBuilderResults = Array.Empty(); + NavMesh = null; + } + public NavMeshBuildResult(IList recastBuilderResults, DtNavMesh navMesh) { + Success = true; RecastBuilderResults = recastBuilderResults; NavMesh = navMesh; } diff --git a/src/DotRecast.Recast.DemoTool/Builder/SoloNavMeshBuilder.cs b/src/DotRecast.Recast.DemoTool/Builder/SoloNavMeshBuilder.cs index 466f83a..f456f48 100644 --- a/src/DotRecast.Recast.DemoTool/Builder/SoloNavMeshBuilder.cs +++ b/src/DotRecast.Recast.DemoTool/Builder/SoloNavMeshBuilder.cs @@ -49,6 +49,11 @@ namespace DotRecast.Recast.DemoTool.Builder filterWalkableLowHeightSpans); var meshData = BuildMeshData(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, rcResult); + if (null == meshData) + { + return new NavMeshBuildResult(); + } + var navMesh = BuildNavMesh(meshData, vertsPerPoly); return new NavMeshBuildResult(ImmutableArray.Create(rcResult), navMesh); } @@ -79,6 +84,11 @@ namespace DotRecast.Recast.DemoTool.Builder DtNavMeshCreateParams option = DemoNavMeshBuilder .GetNavMeshCreateParams(geom, cellSize, cellHeight, agentHeight, agentRadius, agentMaxClimb, result); var meshData = NavMeshBuilder.CreateNavMeshData(option); + if (null == meshData) + { + return null; + } + return DemoNavMeshBuilder.UpdateAreaAndFlags(meshData); } }