gpt4 book ai didi

c# - 更新布局时出现“System.ArithmeticException”

转载 作者:太空狗 更新时间:2023-10-29 19:47:54 24 4
gpt4 key购买 nike

这只发生在 x64 版本中

An unhandled exception of type 'System.ArithmeticException' occurred in WindowsBase.dll Additional information: Overflow or underflow in the arithmetic operation.

在线崩溃

gridcontainer.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);

如果我删除该行,它会在没有可用源的情况下开始更新布局时立即崩溃

00000101  test        ecx,ecx 
00000103 je 0000000000000124
00000105 lea rdx,[rbp+18h]
00000109 mov rcx,qword ptr [rbp+70h]
0000010d call 0000000000216100
00000112 cmp byte ptr [rdi],0

你知道如何预防吗?

异常(exception):

    System.ArithmeticException: Overflow or underflow in the arithmetic operation.
at System.Windows.UIElement.RoundLayoutSize(Size size, Double dpiScaleX, Double dpiScaleY)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.VirtualizingStackPanel.MeasureChild(IItemContainerGenerator& generator, IContainItemStorage& itemStorageProvider, IContainItemStorage& parentItemStorageProvider, Object& parentItem, Boolean& hasUniformOrAverageContainerSizeBeenSet, Double& computedUniformOrAverageContainerSize, Boolean& computedAreContainersUniformlySized, IList& items, Object& item, IList& children, Int32& childIndex, Boolean& visualOrderChanged, Boolean& isHorizontal, Size& childConstraint, Rect& viewport, VirtualizationCacheLength& cacheSize, VirtualizationCacheLengthUnit& cacheUnit, Boolean& foundFirstItemInViewport, Double& firstItemInViewportOffset, Size& stackPixelSize, Size& stackPixelSizeInViewport, Size& stackPixelSizeInCacheBeforeViewport, Size& stackPixelSizeInCacheAfterViewport, Size& stackLogicalSize, Size& stackLogicalSizeInViewport, Size& stackLogicalSizeInCacheBeforeViewport, Size& stackLogicalSizeInCacheAfterViewport, Boolean& mustDisableVirtualization, Boolean isBeforeFirstItem, Boolean isAfterFirstItem, Boolean isAfterLastItem, Boolean skipActualMeasure, Boolean skipGeneration, Boolean& hasBringIntoViewContainerBeenMeasured, Boolean& hasVirtualizingChildren)
at System.Windows.Controls.VirtualizingStackPanel.MeasureOverrideImpl(Size constraint, Nullable`1& lastPageSafeOffset, List`1& previouslyMeasuredOffsets, Boolean remeasure)
at System.Windows.Controls.VirtualizingStackPanel.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
at System.Windows.Controls.ItemsPresenter.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Border.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Control.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.DockPanel.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV, Boolean& hasDesiredSizeUChanged)
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
at System.Windows.UIElement.Measure(Size availableSize)
at System.Windows.ContextLayoutManager.UpdateLayout()
at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

最佳答案

我们偶尔会收到用户的此类报告。问题似乎与浮点单元损坏有关,如 this question 中所述.不幸的是,目前尚不清楚如何在框架调用中处理此类错误。

UPD:我根据演示框架创建了以下解决方法 source code .通过一次调用初始化解决方法:UIHelper.InitWPFArithmeticExceptionWorkaround()

public static class UIHelper
{
[DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int _fpreset();

private static DispatcherOperationCallback _oldUpdateLayoutCallback;
private static object UpdateLayoutCallback(object arg)
{
try
{
_oldUpdateLayoutCallback(arg);
return null;
}
catch (System.Xaml.XamlParseException ex)
{
if (!(ex.InnerException is ArithmeticException))
{
throw;
}
}
// Try to update layout second time after floating point unit reset
_fpreset();
_oldUpdateLayoutCallback(arg);
return null;
}

public static bool InitWPFArithmeticExceptionWorkaround()
{
try
{
// Call fpreset early just to handle case with missed "msvcrt.dll"
// in future Windows versions
_fpreset();
Assembly assembly = typeof(System.Windows.UIElement).Assembly;
Type managerType = assembly.GetType("System.Windows.ContextLayoutManager");
if (managerType != null)
{
FieldInfo field = managerType.GetField("_updateCallback", BindingFlags.Static | BindingFlags.NonPublic);
if (field != null)
{
_oldUpdateLayoutCallback = field.GetValue(null) as DispatcherOperationCallback;
if (_oldUpdateLayoutCallback != null)
{
field.SetValue(null, new DispatcherOperationCallback(UpdateLayoutCallback));
return true;
}
}
}
}
catch
{
}
return false;
}
}

关于c# - 更新布局时出现“System.ArithmeticException”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25311238/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com