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

Should we use LOCK for RenderTargetChanged in relation with OnRender

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

    Should we use LOCK for RenderTargetChanged in relation with OnRender

    I have large indicator, which has heavy OnRender (takes up to 3 seconds in very specific cases).
    However, I have such approach:


    Code:
    private .. myDxBrush;
    
    OnRender(..)
    {
       .... heavy_calculations_block_1();
       .... heavy_calculations_block_2();
       .... heavy_calculations_block_3();
        ... var x = myDxBrush.ToString();
    }
    
    OnRenderTargetChanged()
    {
       myDxBrush.Dispose();
       if (RenderTarget != null)
       {
       .... heavy_calculations_block_other();
           myDxBrush = Brushes.Yellow.ToDxBrush(RenderTarget);
       } 
    }

    strangely, once in a while, very rarely (like 2 hours after using indicator on chart, or on faster markets), i get exception error: object reference not set to instance...
    Yes, there could be an issue with other codes, but is there any chance, that while OnRender is being still executed (and the middle of action, before it reaches to `myDxBrush`), in the meantile OnRenderTargetChanged could have happened, causing to dispose or nullify that property, thus, OnRender finds that property as null.

    is that possible? Should we implement `lock (smthObject)` in OnRender and OnRenderTargetChanged, to avoid such conflict?

    #2
    Hello TazoTodua,

    To confirm, the heavy calculations are for rendering only correct?

    Any calculations that is not specific to rendering values that change based on changing x,y coordinates should not be in OnRender and should be done in OnBarUpdate().

    I am not encountering this error with any scripts I have personally created that do rendering.

    May I confirm you are able to reproduce this behavior with the SampleCustomRender script that is included with NinjaTrader?
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by AaronKoRn, Today, 09:49 PM
    0 responses
    6 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    8 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    9 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,975 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X