forked from mirror/DotRecast
fixed an issue where await deadlock could occur in various platform environments.
This commit is contained in:
parent
7874b4403c
commit
402b25a436
|
@ -97,8 +97,7 @@ namespace DotRecast.Recast.Toolset.Builder
|
|||
filterLowHangingObstacles, filterLedgeSpans, filterWalkableLowHeightSpans,
|
||||
SampleAreaModifications.SAMPLE_AREAMOD_WALKABLE, true);
|
||||
RcBuilder rcBuilder = new RcBuilder();
|
||||
var task = rcBuilder.BuildTilesAsync(geom, cfg, Environment.ProcessorCount + 1, Task.Factory);
|
||||
return task.Result;
|
||||
return rcBuilder.BuildTiles(geom, cfg, Environment.ProcessorCount + 1, Task.Factory);
|
||||
}
|
||||
|
||||
public DtNavMesh BuildNavMesh(IInputGeomProvider geom, List<DtMeshData> meshData, float cellSize, int tileSize, int vertsPerPoly)
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace DotRecast.Recast
|
|||
_progressListener = progressListener;
|
||||
}
|
||||
|
||||
public Task<List<RcBuilderResult>> BuildTilesAsync(IInputGeomProvider geom, RcConfig cfg,
|
||||
public List<RcBuilderResult> BuildTiles(IInputGeomProvider geom, RcConfig cfg,
|
||||
int threads = 0, TaskFactory taskFactory = null, CancellationToken cancellation = default)
|
||||
{
|
||||
RcVec3f bmin = geom.GetMeshBoundsMin();
|
||||
|
@ -56,11 +56,10 @@ namespace DotRecast.Recast
|
|||
|
||||
if (1 < threads)
|
||||
{
|
||||
return BuildMultiThreadAsync(geom, cfg, bmin, bmax, tw, th, threads, taskFactory ?? Task.Factory, cancellation);
|
||||
return BuildMultiThread(geom, cfg, bmin, bmax, tw, th, threads, taskFactory ?? Task.Factory, cancellation);
|
||||
}
|
||||
|
||||
var results = BuildSingleThread(geom, cfg, bmin, bmax, tw, th);
|
||||
return Task.FromResult(results);
|
||||
return BuildSingleThread(geom, cfg, bmin, bmax, tw, th);
|
||||
}
|
||||
|
||||
private List<RcBuilderResult> BuildSingleThread(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tw, int th)
|
||||
|
@ -80,7 +79,7 @@ namespace DotRecast.Recast
|
|||
return results;
|
||||
}
|
||||
|
||||
private async Task<List<RcBuilderResult>> BuildMultiThreadAsync(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tw, int th,
|
||||
private List<RcBuilderResult> BuildMultiThread(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tw, int th,
|
||||
int threads, TaskFactory taskFactory, CancellationToken cancellation)
|
||||
{
|
||||
var results = new ConcurrentQueue<RcBuilderResult>();
|
||||
|
@ -107,12 +106,12 @@ namespace DotRecast.Recast
|
|||
{
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}, null);
|
||||
}, null, cancellation);
|
||||
|
||||
limits.Add(task);
|
||||
if (threads <= limits.Count)
|
||||
{
|
||||
await Task.WhenAll(limits);
|
||||
Task.WaitAll(limits.ToArray());
|
||||
limits.Clear();
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +119,7 @@ namespace DotRecast.Recast
|
|||
|
||||
if (0 < limits.Count)
|
||||
{
|
||||
await Task.WhenAll(limits);
|
||||
Task.WaitAll(limits.ToArray());
|
||||
limits.Clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -78,8 +78,7 @@ public class TestTiledNavMeshBuilder
|
|||
true, true, true,
|
||||
SampleAreaModifications.SAMPLE_AREAMOD_GROUND, true);
|
||||
RcBuilder rcBuilder = new RcBuilder();
|
||||
var task = rcBuilder.BuildTilesAsync(geom, cfg);
|
||||
List<RcBuilderResult> rcResult = task.Result;
|
||||
List<RcBuilderResult> rcResult = rcBuilder.BuildTiles(geom, cfg);
|
||||
|
||||
// Add tiles to nav mesh
|
||||
|
||||
|
|
|
@ -137,8 +137,7 @@ public class RecastTileMeshTest
|
|||
private void Build(IInputGeomProvider geom, RcBuilder builder, RcConfig cfg, int threads, bool validate)
|
||||
{
|
||||
CancellationTokenSource cts = new CancellationTokenSource();
|
||||
var task = builder.BuildTilesAsync(geom, cfg, threads, Task.Factory, cts.Token);
|
||||
List<RcBuilderResult> tiles = task.Result;
|
||||
List<RcBuilderResult> tiles = builder.BuildTiles(geom, cfg, threads, Task.Factory, cts.Token);
|
||||
if (validate)
|
||||
{
|
||||
RcBuilderResult rcResult = GetTile(tiles, 7, 8);
|
||||
|
|
Loading…
Reference in New Issue