Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Reusing DX brushes in OnRender()

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

    Reusing DX brushes in OnRender()

    Hi,

    I have an efficiency/performance question regarding reusing DX brushes during calls to OnRender().

    I understand that it is not efficient to recreate brushes during each call to OnRender(). This leaves me with two options:

    Option A:
    Inside OnRender() I can set

    Code:
    SharpDX.Direct2D1.Brush areaBrushDX = areaBrush.ToDxBrush(RenderTarget);
    SharpDX.Direct2D1.Brush textBrushDX  = textBrush.ToDxBrush(RenderTarget);
    and dispose of the brushes at the end of OnRender().

    Alternatively, I can have

    Option B:
    Inside OnRenderTargetChanged() I can set

    Code:
            public override void OnRenderTargetChanged()
            {
                if (areaBrushDx != null)
                    areaBrushDx.Dispose();
    
                if (textBrushDx != null)
                    textBrushDx.Dispose();
    
                if (RenderTarget != null)
                {
                    try
                    {
                        areaBrushDx            = areaBrush.ToDxBrush(RenderTarget);
                        textBrushDx            = textBrush.ToDxBrush(RenderTarget);
                    }
                    catch (Exception e) { }
                }
            }
    I have two questions:
    1. Which option is most efficient in terms of resources and performance?
    2. Which option should be used if you have a lot of brushes you need to use?

    Thank you.

    #2
    Hello Zeos6,

    It is most efficient to create the brushes when the render target changes in OnRenderTargetChanged() when it is necessary to.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      You may easily test the case by inserting print instructions in both OnRender and OnRenderTargetChanged.

      Have a look at the output window, and you will exactly know when OnRenderTargetChanged() and OnRender() are being called.

      As OnRender() is being called many more times than OnRenderTargetChanged(), it is best practice to create and dispose of DX brushes in OnRenderTargetChanged(). This is particularly true, as conversion of System.Media.Brushes to DX brushes is an "expensive" process.

      Thank you for posting this question, as I am sure that other users will appreciate this question as well.
      Last edited by Harry; 05-28-2018, 06:41 AM.

      Comment


        #4
        Thank you ChelseaB and Harry. Harry, I appreciate the information and your insight on this matter. I already handle strokes via OnRenderTargetChanged() so I will simply add handling brushes here as well. Thank you once again.

        Comment


          #5
          NT 8.0.14 breaks all our indicators with custom OnRender() sections

          It seems that NT 8.0.14 has broken all our indicators that use OnRenderTargetChanged() to set and dispose of DX brushes.

          All indicators that follow the approach of declaring DX brushes in the variables section, then set DX brushes in OnRenderTargetChanged() and access those brushes in OnRender() are throwing exceptions most of the time.

          We are also seeing issue with synchronization between State.Configure() and OnRenderTargetChanged(), as OnRenderTargetChanged() is called prior to the completion of State.Configure.

          The behavior is specific to the release NT 8.0.14.1 and did not occur with prior releases.

          Beware of release NT 8.0.14.1!

          This is a huge desaster, as nothing works anymore.

          NT 8.0.13.1 was just fine and did not show this behavior.
          Last edited by Harry; 06-09-2018, 04:04 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by techgetgame, Today, 11:42 PM
          0 responses
          7 views
          0 likes
          Last Post techgetgame  
          Started by sephichapdson, Today, 11:36 PM
          0 responses
          1 view
          0 likes
          Last Post sephichapdson  
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,612 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          9 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          19 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Working...
          X