From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Slice range must fall within the size of the buffer.

Solved!
Go to solution

Hi,

 

I am pretty baffled about this problem. I have a Graph binded with an array of Chartcollections. The charts are filled paralelly. Sometimes, quite randomly, I get this exception. In this case i had three plots displayed:

 

System.ArgumentOutOfRangeException was unhandled
  HResult=-2146233086
  Message=Slice range must fall within the size of the buffer.
Parameter name: length
Actual value was 3.
  Source=NationalInstruments.Common
  ParamName=length
  StackTrace:
       at NationalInstruments.Restricted.Guard`1.Satisfies(Boolean condition, Func`4 exceptionCreator, String format, Object[] args)
       at NationalInstruments.Restricted.NIValidation.IsInRange[T](Guard`1 guard, Boolean isInRange, String format, Object[] args)
       at NationalInstruments.DataInfrastructure.Primitives.RawDataStore`1.Slice(Int32 startIndex, Int32 length)
       at NationalInstruments.DataInfrastructure.Buffer`1.Slice(Int32 startIndex, Int32 length, Func`2 traitFilter)
       at NationalInstruments.DataInfrastructure.Buffer`1.NationalInstruments.DataInfrastructure.IBuffer.Slice(Int32 startIndex, Int32 length)
       at NationalInstruments.Controls.Internal.DefaultAdjusterStep.a(IDictionary`2 A_0)
       at NationalInstruments.Controls.Internal.DefaultAdjusterStep.c(IDictionary`2 A_0)
       at NationalInstruments.Controls.Internal.DefaultPipelineDataProcessor.a(DefaultDataItemDescription[] A_0)
       at NationalInstruments.Controls.Internal.DefaultPipelineDataProcessor.a()
       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)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       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)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(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(Window window)
       at System.Windows.Application.Run()
       at MyProject.FinalTest.Specific.GUI.App.Main() in c:\Sandbox\Specific2\MyProject.FinalTest.Specific.GUI\obj\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 

I dont even know where to start looking! Can someone please give me some pointers? Thanks!

0 Kudos
Message 1 of 3
(4,393 Views)

By "The charts are filled parallelly", I take it that you are always appending to all the charts at the same time? Or do you mean appending to the charts on a different thread? (If the latter, because the chart collections are not thread-safe, you would need to marshal appends to the UI thread.)

 

Unfortunately, I was not able to reproduce the slice error you are seeing. I used three ChartCollection<double> instances, and tested appending the same number of samples to each and different number of samples to each from a dispatcher timer, using one or two vertical axes. If you could provide a small sample application that reproduces the error, it would greatly simplify debugging your issue.

 

As a workaround, you may want to use the suggestions from this answer about disappearing charts. This will prevent the slice method from being called, which should avoid the issue entirely.

~ Paul H
0 Kudos
Message 2 of 3
(4,379 Views)
Solution
Accepted by topic author jtamaska

I found the problem!

 

I had a timer calling the method, which updated the plots from a queue. If there were too many signals, the emptying of the queue could take longer  than the next timer call, and two threads tried to acces the charts paralel. I know set the timer inactive for the queue reading and turn it on after, and the problem looks solved!

 

Thank you for the idea bouncing, it was the direction I needed to start looking!

0 Kudos
Message 3 of 3
(4,367 Views)