question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.Windows.Vector.Normalize() can throw DivideByZeroException

See original GitHub issue
  • .NET Core Version: 6.0
  • Windows version: Windows 10

I have only the exception stack trace collected automatically from one of my clients. No other system information is available.

I do not know how to reproduce this issue.

I hope that this stack trace would be useful for some research.

Vector class can throw this exception when its_x and _y fields are equal to 0.

Line of code that raised the exception:

DropDown.IsOpen = true;

where DropDown has type System.Windows.Controls.ContextMenu.

System.DivideByZeroException: Attempted to divide by zero.
at void System.Windows.Vector.Normalize()
at void System.Windows.Controls.Primitives.Popup.UpdatePosition()
at void System.Windows.Controls.Primitives.Popup.Reposition()
at void System.Windows.Controls.Primitives.Popup.OnWindowResize(object sender, AutoResizedEventArgs e)
at void System.Windows.Interop.HwndSource.Resize(Size newSize)
at void System.Windows.Interop.HwndSource.OnLayoutUpdated(object obj, EventArgs args)
at void System.Windows.ContextLayoutManager.fireLayoutUpdateEvent()
at void System.Windows.ContextLayoutManager.UpdateLayout()
at void System.Windows.Interop.HwndSource.SetLayoutSize()
at void System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
at void System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
at void System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot()
at void System.Windows.Controls.Primitives.Popup.CreateWindow(bool asyncCall)
at void System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at void System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at void System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at void System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at UpdateResult System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, ref EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, OperationType operationType)
at void System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, object value, PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, OperationType operationType, bool isInternal)
at void System.Windows.DependencyObject.SetValue(DependencyProperty dp, object value)
at BindingExpressionBase System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)
at void System.Windows.Controls.Primitives.Popup.CreateRootPopupInternal(Popup popup, UIElement child, bool bindTreatMousePlacementAsBottomProperty)
at void System.Windows.Controls.ContextMenu.HookupParentPopup()
at void System.Windows.Controls.ContextMenu.OnIsOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at void System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at void System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at void System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at UpdateResult System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, ref EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, OperationType operationType)
at void System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, object value, PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, OperationType operationType, bool isInternal)
at void System.Windows.DependencyObject.SetValue(DependencyProperty dp, object value)
at void System.Windows.Controls.ContextMenu.set_IsOpen(bool value)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
singhashish-wpfcommented, Aug 5, 2022

@VladimirKhil Thanks for the issue. For now, we will be closing this. For the next time it’ll be great if we have a memory dump or a reliable minimal repro to check this. Thanks @miloush for the follow up 👍

0reactions
VladimirKhilcommented, Aug 4, 2022

That sounds much more plausible. Is your application calling any native code around this codepath?

No, there are no native calls nearby. But there are a few in the whole application. One of it or maybe some native call in WPF itself could be the root cause.

Sorry, but it seems that the root cause could not be discovered easily. The problem is very rare. So maybe it is better to just close the issue until any new similar cases happen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any reason to throw a DivideByZeroException?
"You can't divide by zero" adds no value. However, you can avoid many of these exceptions by screening the values passed by the...
Read more >
DivideByZeroException Class (System)
The exception that is thrown when there is an attempt to divide an integral or Decimal value by zero.
Read more >
Handling div by zero in game dev. : r/gamedev
Generally whatever is calling for the division should ensure it's not dividing by zero, and the normalize is the exception because you'll want ......
Read more >
Normalized vector added to vector returning NaN
When you normalize the vector, you divide each component (x and y) by the length. If they're the same position, the length will...
Read more >
TS3 SimRipper beta testing requested - V0.6.0 1/29/2022
System.DivideByZeroException: Cannot normalize a vector with magnitude of zero! at TS3SimRipper.Vector3.Normalize(Vector3 v1)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found