Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

wpf graph error: Cannot draw outside of a draw cycle

I get this error sometimes after adding new plot to the graph:

 

graph.Plots.Add(_newPlot);
graph.Data[_newPlot.Index] = graph.Data[_plot.Index];

 

How do I prevent this?

0 Kudos
Message 1 of 11
(6,760 Views)

Sorry, what is the error? I think you didn't attach something.

Jeff | LabVIEW Software Engineer
0 Kudos
Message 2 of 11
(6,759 Views)

Cannot draw outside of a draw cycle

 

I don't see where this exception is coming from

0 Kudos
Message 3 of 11
(6,757 Views)

There is a known issue with how the graph performs rendering in the current release of Measurement Studio (in that case, resizing the graph while it was rendering caused the exception).


I created a project containing a graph with one plot and a button with the code below, but was not able to reproduce your issue:


    int i = graph.Plots.Count;
    graph.Plots.Add( new Plot() );
    graph.Data[i] = graph.Data[i - 1];

~ Paul H
0 Kudos
Message 4 of 11
(6,748 Views)

Maybe difference is that I output data to the graph all the time in parallel. Should I use some lock on the graph?

0 Kudos
Message 5 of 11
(6,727 Views)

In general, UI controls are tied to the UI therad and cannot be updated in parallel. There are some specific scenarios where we support observed updates with later DAQmx driver versions, but in general all changes need to go through the UI thread.

~ Paul H
0 Kudos
Message 6 of 11
(6,722 Views)

I update graph data using Invoke, and also add plots in UI thread, so this shouldn't be an issue...

0 Kudos
Message 7 of 11
(6,718 Views)

Could you provide a sample program that reproduces the issue? Or at least post the stack trace in the exception?

~ Paul H
0 Kudos
Message 8 of 11
(6,709 Views)

Don't know if this was ever fixed but I get the same error sometimes when manipulating a RangeCursor while the graph is updating.  Here is the stack trace below.  NOTE: I am not on the latest NI libraries yet, I haven't updated in about 7 months.

 

 Stack Trace:    at NationalInstruments.Restricted.Guard`1.Satisfies(Boolean condition, Func`4 exceptionCreator, String format, Object[] args)
   at NationalInstruments.Restricted.NIValidation.IsEqualTo[T](Guard`1 guard, T expected, String format, Object[] args)
   at NationalInstruments.Controls.Internal.VectorRenderTargetBase.a(RenderTargetOptions A_0)
   at NationalInstruments.Controls.Internal.VectorRenderTargetBase.a(RenderTargetOptions A_0, Buffer`1 A_1, Buffer`1 A_2)
   at NationalInstruments.Controls.Internal.VectorRenderTargetBase.DrawArea(RenderTargetOptions options, Buffer`1 xRelativeValues, Buffer`1 yRelativeValues)
   at NationalInstruments.Controls.RangeCursor.RenderGraphCore(RenderArgs args)
   at NationalInstruments.Controls.Primitives.CursorBase.NationalInstruments.Controls.Rendering.IRenderable.Render(RenderArgs args)
   at NationalInstruments.Controls.Internal.RenderTargetHelper.RenderInDrawCycle(IRenderable renderer, RenderArgs args)
   at NationalInstruments.Controls.Primitives.RenderArea.a(Object A_0)
   at NationalInstruments.Controls.Primitives.RenderArea.a()
   at NationalInstruments.Controls.Primitives.PlotArea.OnSizeChanged(Object A_0, SizeChangedEventArgs A_1)
   at System.Windows.SizeChangedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.FrameworkElement.OnRenderSizeChanged(SizeChangedInfo sizeInfo)
   at System.Windows.ContextLayoutManager.fireSizeChangedEvents()
   at System.Windows.ContextLayoutManager.UpdateLayout()
   at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
   at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
   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) 
0 Kudos
Message 9 of 11
(6,506 Views)

From the "PlotArea.O​nSizeChanged" call in your stack trace, I think your problem is more likely related to this question, which was fixed in Measurement Studio 2013.

~ Paul H
0 Kudos
Message 10 of 11
(6,502 Views)