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

OnRenderTargetChanged

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

    OnRenderTargetChanged

    Can I use the pattern of disposing and reinitializing in OnRenderTargetChanged() for TextFormat and StrokeStyleProperties.

    Code:
    SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(Core.Globals.DirectWriteFactory, txtFont.Family.ToString(), SharpDX.DirectWrite.FontWeight.Bold,
    														SharpDX.DirectWrite.FontStyle.Normal, SharpDX.DirectWrite.FontStretch.Normal, 16);

    Code:
    SharpDX.Direct2D1.StrokeStyleProperties ssProps = new SharpDX.Direct2D1.StrokeStyleProperties();
    ssProps.DashStyle = dashStyle;
    SharpDX.Direct2D1.StrokeStyle myStyle = new SharpDX.Direct2D1.StrokeStyle(helper.renderTarget.Factory, ssProps);
    If yes what would it look like

    Thank you
    Last edited by blar58; 06-23-2017, 11:50 AM.

    #2
    Hello blar58,

    Thanks for opening the thread.

    Device dependent resources will need to be disposed of in OnRenderTargetChanged() so the resources can be freed with each render target change. SharpDX Brushes are an example of a device dependent resource.

    Device independent resources would not need to be disposed of inside OnRenderTargetChanged(). As SharpDX.DirectWrite.TextFormat and SharpDX.Direct2D1.StrokeStyle are considered device independent, you would not need to dispose of these objects with each render target change.

    SharpDX.Direct2D1.StrokeStyleProperties does not inherit an IDisposable property, so it would not be able to be disposed of.

    It is recommended to dispose of all objects that inherit an IDisposable property, but you only need to worry about the device dependent resources getting disposed and recreated in OnRenderTargetChanged().

    You can reference the SampleCustomRender indicator to see how TextFormats can be disposed of in OnRender(). As this is a device-indpendent resource, it could be disposed of in State.Terminated instead.

    You may reference the links below for further reading and usage.

    DisposeBase (Disposable objects) - https://ninjatrader.com/support/help...isposebase.htm

    OnRenderTargetChanged (only device dependent resources need to be disposed of here) - https://ninjatrader.com/support/help...getchanged.htm

    DirectWrite (device independent) - https://msdn.microsoft.com/en-us/lib.../dd368038.aspx

    StrokeStyle (device independent) - https://ninjatrader.com/support/help...trokestyle.htm

    StrokeStyleProperties (does not inherit IDisposable) - https://ninjatrader.com/support/help...properties.htm

    EDIT: The best practices link here covers what is device dependent and independent - https://ninjatrader.com/support/help...arpDXResources

    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_Jim; 06-23-2017, 02:33 PM.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks for your answer Jim

      I have a question though.
      I looked at the sampleCustomRender indicator and I am wondering if creating a new SimpleFont in OnRender() each time the chart updates would that not be resource intensive instead of creating the SimpleFont only once ?

      Comment


        #4
        Jim

        Just discard my last reply.

        I figured out what to do

        Thanks

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        30 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        943 views
        0 likes
        Last Post spwizard  
        Started by Max238, Today, 01:28 AM
        0 responses
        9 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by rocketman7, Today, 01:00 AM
        0 responses
        4 views
        0 likes
        Last Post rocketman7  
        Started by wzgy0920, 04-20-2024, 06:09 PM
        2 responses
        28 views
        0 likes
        Last Post wzgy0920  
        Working...
        X