task - 在任务数组中检测碰撞(Eyeshot)的问题
问题描述
我正在尝试检查不同任务中的每个动作,并在检查是否存在碰撞后,在某些迭代中它会生成一个异常“源矩阵不够长或不够。检查索引和长度,以及较低的矩阵的极限。” 如果您尝试在“for”中按顺序运行,则不会发生错误,我需要并行运行以提高性能。在调试测试中,我注意到尝试运行 cd.DoWork() 时总是发生错误
private void btn_Tasks_Click(object sender, EventArgs e)
{
// The source of your work items, create a sequence of Task instances.
Task[] tasks = Enumerable.Range(0,tabelaPosicao.Count).Select(i =>
// Create task here.
Task.Run(() =>
{
VerifiCollision(i);
})
// No signalling, no anything.
).ToArray();
// Wait on all the tasks.
Task.WaitAll(tasks);
}
private void VerifiCollision(object x)
{
int xx = (int)x;
int AuxIncrMorsa = Convert.ToInt32(tabelaPosicao[xx].Posicao) * -1;
bRef_BaseMorsa.Transformation = new Translation(0, AuxIncrMorsa, 0);
CollisionDetection cd = new CollisionDetection(new List<Entity>() { bRef_BaseMorsa }, new List<Entity>() { bRef_Matriz }, model1.Blocks, true, CollisionDetection2D.collisionCheckType.OBWithSubdivisionTree, maxTrianglesNumForOctreeNode: 5);
{
if (cd != null)
{
try
{
cd.DoWork();
}
catch (Exception e)
{
e.StackTrace;
}
catch (AggregateException ae)
{
var messege = ae.Message;
}
}
model1.Entities.ClearSelection();
if (cd3.Result != null && cd3.Result.Count > 0)
{
tabelaPosicao[xx].Tuple = new Tuple<string, string>(cd3.Result[0].Item1.ParentName,
cd3.Result[0].Item2.ParentName);
}
}
}
解决方案
在应用转换之前,您需要克隆实体。你可以看看这篇文章的“WORKFLOW”主题。
推荐阅读
- java - 如何在 java/android 中将 JPG 图像转换为字符串
- android - 如何阻止 RecyclerView 中的视图在获得焦点时更新其值?
- mysql - .Net Core 3 Mysql Pomelo DateTime 不兼容
- java - 为什么在编写 UnitTest 时得到空响应
- c# - 以表格形式显示今天的日期(asp.net core)
- core-data - SwiftUI CoreData MVVM 解决错误“EXC_BAD_INSTRUCTION....”
- ios - 在 SwiftUI 中制作自定义 ButtonStyle(适用于 MacOS)
- java - 'android.content.Context.getApplicationInfo()' 上的空指针异常
- flutter - 为什么在这里使用 StatelessWidget 可以正常工作?
- azure-data-explorer - 检查热缓存中数据实际占用大小的可靠方法