Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    589 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    342 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    555 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    552 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X