Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exception within ChartControl.get_PanelWidthPixels

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Exception within ChartControl.get_PanelWidthPixels

    Hi,

    This rare exception happened and thought I should pass it on as it looks unrelated to my code. Looks like a lock is missing on some collection within get_PanelWidthPixels().

    Exception: Collection was modified; enumeration operation may not execute.
    at System.ThrowHelper.ThrowInvalidOperationException( ExceptionResource resource)
    at System.Collections.Generic.List`1.Enumerator.MoveN extRare()
    at System.Linq.Enumerable.WhereSelectEnumerableIterat or`2.MoveNext()
    at System.Linq.Enumerable.Max(IEnumerable`1 source)
    at NinjaTrader.Gui.Chart.ChartControl.get_PanelWidthPixels()
    at NinjaTrader.Gui.Chart.ChartControl.get_CanvasRight ()
    at NinjaTrader.Gui.Chart.ChartControl.GetXBySlotIndex (Double slotIndex)
    at NinjaTrader.Gui.Chart.ChartControl.GetXByBarIndex( ChartBars chartBars, Int32 barIndex)
    at NinjaTrader.NinjaScript.DrawingTools.DrawingTool.C reateChartAnchor(NinjaScriptBase ownerNinjaScript, Int32 barsAgo, DateTime time, Double y)
    at NinjaTrader.NinjaScript.DrawingTools.Draw.DrawLine TypeCore[T](NinjaScriptBase owner, Boolean isAutoScale, String tag, Int32 startBarsAgo, DateTime startTime, Double startY, Int32 endBarsAgo, DateTime endTime, Double endY, Brush brush, DashStyleHelper dashStyle, Int32 width, Boolean isGlobal, String templateName) in d:\Documents\NinjaTrader 8\bin\Custom\DrawingTools\@Lines.cs:line 730
    at NinjaTrader.NinjaScript.DrawingTools.Draw.Line(Nin jaScriptBase owner, Boolean isAutoScale, String tag, Int32 startBarsAgo, DateTime startTime, Double startY, Int32 endBarsAgo, DateTime endTime, Double endY, Brush brush, DashStyleHelper dashStyle, Int32 width) in d:\Documents\NinjaTrader 8\bin\Custom\DrawingTools\@Lines.cs:line 1257
    at NinjaTrader.NinjaScript.DrawingTools.Draw.Line(Nin jaScriptBase owner, String tag, Boolean isAutoScale, Int32 startBarsAgo, Double startY, Int32 endBarsAgo, Double endY, Brush brush, DashStyleHelper dashStyle, Int32 width) in d:\Documents\NinjaTrader 8\bin\Custom\DrawingTools\@Lines.cs:line 1293
    at NinjaTrader.NinjaScript.Indicators.Crokusek.Crokus ekIndicatorBase.DrawLine(String tag, Boolean isAutoScale, Int32 startBarsAgo, Double startY, Int32 endBarsAgo, Double endY, Color color, Int32 width, DashStyleHelper dashStyle) in d:\Documents\NinjaTrader 8\bin\Custom\Indicators\Crokusek\CrokusekIndicator Base.cs:line 45
    at NinjaTrader.NinjaScript.Indicators.Crokusek.LomoHi mo.DrawPricePanelStackedMids(Int32 agoOffset) in d:\Documents\NinjaTrader 8\bin\Custom\Indicators\Crokusek\LomoHimo.cs:line 642
    at NinjaTrader.NinjaScript.Indicators.Crokusek.LomoHi mo.DrawPricePanelSignals() in d:\Documents\NinjaTrader 8\bin\Custom\Indicators\Crokusek\LomoHimo.cs:line 438
    at NinjaTrader.NinjaScript.Indicators.Crokusek.LomoHi mo.CalculateCurrentExpectedValue() in d:\Documents\NinjaTrader 8\bin\Custom\Indicators\Crokusek\LomoHimo.cs:line 396
    at NinjaTrader.NinjaScript.Indicators.Crokusek.LomoHi mo.OnBarUpdateInternal() in d:\Documents\NinjaTrader 8\bin\Custom\Indicators\Crokusek\LomoHimo.cs:line 219
    at NinjaTrader.NinjaScript.Indicators.Crokusek.Crokus ekIndicatorBase.OnBarUpdate() in d:\Documents\NinjaTrader 8\bin\Custom\Indicators\Crokusek\CrokusekIndicator Base.cs:line 79


    Please don't request workspace/trace as it is mostly custom and I think the exception is unrelated. Here is basically how it was triggered though:

    Within OnBarUpdate(), using this pattern to update existing line:

    Code:
                    ChartShape prevShape;
                    if (_shapes.TryGet(prevTag, out prevShape))  
                    {
                        DrawingTools.Line prevLine = prevShape.Shape as DrawingTools.Line;
    
                        prevShape.Update(DrawLine(prevShape.OrgTag, 
                            false, prevLine.StartAnchor.BarsAgo + 1, prevLine.StartAnchor.Price, agoOffset, atY, color, 3), tag);                        
                    }
                    else
                        _shapes.Add(DrawLine(tag, false, 1 + agoOffset, atY, agoOffset, atY, color, 4, DashStyleHelper.Dash));
    Thanks,
    Chris

    #2
    Hello Chris,

    Thank you for your post.

    What type is ChartShape? Can you provide the code for this collection type?

    I look forward to your response.

    Comment


      #3
      I'm sorry but ChartShape is so interconnected with so much other custom code that providing it will just blow up the complexity. Its operation is simple though--it retrieves an existing line/region by tag name, casts it to its original type (Line or Region) and then adds a new line/region that replaces the original by using the same tag.

      The stack trace doesn't look related directly to this sequence of events anyway. Just inspecting the code in that area would probably show some collection that is not strictly thread safe. The exception has only happened a few times so far afaik and this sequence of events has been running for days so its not a big deal. Just fyi really.

      Comment


        #4
        Hello crokusek,

        Thank you for your response.

        I will forward to development. Would we be able to test the full script on our end? If so, can you send it over to platformsupport[at]ninjatrader[dot]com with this thread as reference?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        18 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        1 view
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        6 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        41 views
        0 likes
        Last Post alifarahani  
        Working...
        X