首页 > 解决方案 > 在任务数组中检测碰撞(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);

            }
         }

    }

标签: taskcollisiondetectioneyeshot

解决方案


在应用转换之前,您需要克隆实体。你可以看看这篇文章的“WORKFLOW”主题。


推荐阅读