Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\limsup throws exception #244

Closed
ForNeVeR opened this issue Jan 12, 2020 · 4 comments · Fixed by #286
Closed

\limsup throws exception #244

ForNeVeR opened this issue Jan 12, 2020 · 4 comments · Fixed by #286
Assignees
Labels

Comments

@ForNeVeR
Copy link
Owner

Try to parse the following formula: \limsup

It will break the library:

Unhandled exception. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.ArgumentException: An item with the same key has already been added. Key: f
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at WpfMath.TexPredefinedFormulaParser.CreateTeXFormulaParser.Parse(SourceSpan source, XElement element) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexPredefinedFormu
laParser.cs:line 175
   at WpfMath.TexPredefinedFormulaParser.ParseFormula(SourceSpan source, XElement formulaElement) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexPredefinedFormulaParser.
cs:line 117
   at WpfMath.TexPredefinedFormulaParser.<>c__DisplayClass10_0.<Parse>b__0(SourceSpan source) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexPredefinedFormulaParser.cs:l
ine 103
   at WpfMath.TexFormulaParser.ProcessEscapeSequence(TexFormula formula, SourceSpan value, Int32& position, Boolean allowClosingDelimiter, Boolean& closedDelimiter, ICom
mandEnvironment environment) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 652
   at WpfMath.TexFormulaParser.Parse(SourceSpan value, Int32& position, Boolean allowClosingDelimiter, String textStyle, ICommandEnvironment environment) in D:\X-Files\P
rojects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 246
   at WpfMath.TexFormulaParser.Parse(String value, String textStyle) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 166
   at WpfMath.TexPredefinedFormulaParser.CreateTeXFormulaParser.Parse(SourceSpan source, XElement element) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexPredefinedFormu
laParser.cs:line 168
   at WpfMath.TexPredefinedFormulaParser.ParseFormula(SourceSpan source, XElement formulaElement) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexPredefinedFormulaParser.
cs:line 117
   at WpfMath.TexPredefinedFormulaParser.<>c__DisplayClass10_0.<Parse>b__0(SourceSpan source) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexPredefinedFormulaParser.cs:l
ine 103
   at WpfMath.TexFormulaParser.ProcessEscapeSequence(TexFormula formula, SourceSpan value, Int32& position, Boolean allowClosingDelimiter, Boolean& closedDelimiter, ICom
mandEnvironment environment) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 652
   at WpfMath.TexFormulaParser.Parse(SourceSpan value, Int32& position, Boolean allowClosingDelimiter, String textStyle, ICommandEnvironment environment) in D:\X-Files\P
rojects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 246
   at WpfMath.TexFormulaParser.Parse(SourceSpan value, String textStyle, ICommandEnvironment environment) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormulaParser.cs
:line 177
   at WpfMath.TexFormulaParser.ProcessEscapeSequence(TexFormula formula, SourceSpan value, Int32& position, Boolean allowClosingDelimiter, Boolean& closedDelimiter, ICom
mandEnvironment environment) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 667
   at WpfMath.TexFormulaParser.Parse(SourceSpan value, Int32& position, Boolean allowClosingDelimiter, String textStyle, ICommandEnvironment environment) in D:\X-Files\P
rojects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 246
   at WpfMath.TexFormulaParser.Parse(String value, String textStyle) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 166
   at WpfMath.TexFormulaHelper.AddOperator(String operatorFormula, Boolean useVerticalLimits) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormulaHelper.cs:line 158
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at WpfMath.TexPredefinedFormulaParser.MethodInvocationParser.Parse(SourceSpan source, XElement element) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexPredefinedFormu
laParser.cs:line 144
   at WpfMath.TexPredefinedFormulaParser.ParseFormula(SourceSpan source, XElement formulaElement) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexPredefinedFormulaParser.
cs:line 117
   at WpfMath.TexPredefinedFormulaParser.<>c__DisplayClass10_0.<Parse>b__0(SourceSpan source) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexPredefinedFormulaParser.cs:l
ine 103
   at WpfMath.TexFormulaParser.ProcessEscapeSequence(TexFormula formula, SourceSpan value, Int32& position, Boolean allowClosingDelimiter, Boolean& closedDelimiter, ICom
mandEnvironment environment) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 652
   at WpfMath.TexFormulaParser.Parse(SourceSpan value, Int32& position, Boolean allowClosingDelimiter, String textStyle, ICommandEnvironment environment) in D:\X-Files\P
rojects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 246
   at WpfMath.TexFormulaParser.Parse(String value, String textStyle) in D:\X-Files\Projects\wpf-math\src\WpfMath\TexFormulaParser.cs:line 166
   at WpfMath.Controls.FormulaControl.CoerceFormula(DependencyObject d, Object baseValue) in D:\X-Files\Projects\wpf-math\src\WpfMath\Controls\FormulaControl.xaml.cs:lin
e 165
   at System.Windows.DependencyObject.ProcessCoerceValue(DependencyProperty dp, PropertyMetadata metadata, EntryIndex& entryIndex, Int32& targetIndex, EffectiveValueEntr
y& newEntry, EffectiveValueEntry& oldEntry, Object& oldValue, Object baseValue, Object controlValue, CoerceValueCallback coerceValueCallback, Boolean coerceWithDeferredR
eference, Boolean coerceWithCurrentValue, Boolean skipBaseValueChecks)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, Effecti
veValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
   at System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp)
   at System.Windows.Data.BindingExpressionBase.Invalidate(Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.TransferValue(Object newValue, Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.ScheduleTransfer(Boolean isASubPropertyChange)
   at MS.Internal.Data.ClrBindingWorker.NewValueAvailable(Boolean dependencySourcesChanged, Boolean initialValue, Boolean isASubPropertyChange)
   at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
   at MS.Internal.Data.PropertyPathWorker.OnDependencyPropertyChanged(DependencyObject d, DependencyProperty dp, Boolean isASubPropertyChange)
   at MS.Internal.Data.ClrBindingWorker.OnSourceInvalidation(DependencyObject d, DependencyProperty dp, Boolean isASubPropertyChange)
   at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
   at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
   at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, Effecti
veValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceW
ithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetCurrentDeferredValue(DependencyProperty dp, DeferredReference deferredReference)
   at System.Windows.Controls.TextBox.OnTextContainerChanged(Object sender, TextContainerChangedEventArgs e)
   at System.Windows.Documents.TextContainer.EndChange(Boolean skipEvents)
   at System.Windows.Documents.TextContainer.System.Windows.Documents.ITextContainer.EndChange(Boolean skipEvents)
   at System.Windows.Documents.TextRangeBase.EndChange(ITextRange thisRange, Boolean disableScroll, Boolean skipEvents)
   at System.Windows.Documents.TextRange.System.Windows.Documents.ITextRange.EndChange(Boolean disableScroll, Boolean skipEvents)
   at System.Windows.Documents.TextRange.ChangeBlock.System.IDisposable.Dispose()
   at System.Windows.Documents.TextEditorTyping.DoTextInput(TextEditor This, String textData, Boolean isInsertKeyToggled, Boolean acceptControlCharacters)
   at System.Windows.Documents.TextEditorTyping.TextInputItem.Do()
   at System.Windows.Documents.TextEditorTyping.ScheduleInput(TextEditor This, InputItem item)
   at System.Windows.Documents.TextEditorTyping.OnTextInput(Object sender, TextCompositionEventArgs e)
   at System.Windows.Controls.Primitives.TextBoxBase.OnTextInput(TextCompositionEventArgs e)
   at System.Windows.UIElement.OnTextInputThunk(Object sender, TextCompositionEventArgs e)
   at System.Windows.Input.TextCompositionEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.TextCompositionManager.UnsafeCompleteComposition(TextComposition composition)
   at System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
   at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.TextCompositionManager.UnsafeStartComposition(TextComposition composition)
   at System.Windows.Input.TextCompositionManager.PostProcessInput(Object sender, ProcessInputEventArgs e)
   at System.Windows.Input.InputManager.RaiseProcessInputEventHandlers(ProcessInputEventHandler postProcessInput, ProcessInputEventArgs processInputEventArgs)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndKeyboardInputProvider.ProcessTextInputAction(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at System.Windows.Interop.HwndSource.OnPreprocessMessageThunk(MSG& msg, Boolean& handled)
   at System.Windows.Interop.ComponentDispatcherThread.RaiseThreadMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.Run()
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run()
   at WpfMath.Example.App.Main()

@ForNeVeR
Copy link
Owner Author

@rstm-sf, wanna take a look? It could be one of the cases I've declared to lie "a bit deeper" while reviewing your #214.

@rstm-sf
Copy link
Contributor

rstm-sf commented Jan 12, 2020

Hmm, I overlooked and did not assume that this is possible
https://github.com/ForNeVeR/wpf-math/blob/36707619581933b6c9fef213627fdb7beb24236b/src/WpfMath/Data/PredefinedTexFormulas.xml#L524-L531

But I don’t feel like doing xml -> c# yet :) I hope we also find a workaround there

@rstm-sf
Copy link
Contributor

rstm-sf commented Jan 12, 2020

Wow, now I began to understand more how TexFormulaHelper is used

@ForNeVeR
Copy link
Owner Author

I will throw some more docs into TexFormulaHelper in my nearest PR. And, yeah, I have no plans to dramatically enhance TexFormulaHelper and TexPredefinedFormulas.xml, I want to remove them completely and encourage the users (ourselves included) to write formulas in typesafe C# instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants