UWP - InkCanvas上的InkToolbar上的自定义撤消和重做 - System.ExecutionEngineException未处理

时间:2016-10-07 21:22:26

标签: uwp windows-10-universal inkcanvas

尝试在InkCanvas上创建自定义撤消和重做。然而,经过一些压力测试(添加大量笔画,撤消和重做很多次),应用程序崩溃:

  

System.ExecutionEngineException未处理。的HResult = -2146233082

在我的AddToRedoList方法的foreach循环上。任何人都有任何想法如何捕获和修复异常?

private void AddToRedoList(InkStroke addStroke) {
  var addInkPoint = addStroke.GetInkPoints();
  var addInkPointList = new List<InkPoint>();
  foreach (var point in addInkPoint) {
    addInkPointList.Add(new InkPoint(point.Position, point.Pressure));
  }

  redoCustomStrokeList.Add(new CustomStroke() {
    InkPoints = addInkPointList,
    DrawingAttributes = addStroke.DrawingAttributes
  });
}

private void UndoOnClick(object sender, RoutedEventArgs e) {
  var allStrokes = InkImage.InkPresenter.StrokeContainer.GetStrokes();
  var undoStroke = allStrokes[allStrokes.Count - 1];
  AddToRedoList(undoStroke);

  allStrokes[allStrokes.Count - 1].Selected = true;
  InkImage.InkPresenter.StrokeContainer.DeleteSelected();
}

private void RedoOnClick(object sender, RoutedEventArgs e) {
  var lastRedoInkPoints = redoCustomStrokeList[redoCustomStrokeList.Count-1];
  InkImage.InkPresenter.StrokeContainer.AddStroke(CreateStroke(lastRedoInkPoints));
    redoCustomStrokeList.Remove(lastRedoInkPoints);
  }
}

0 个答案:

没有答案