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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    52 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    71 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    38 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    99 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    60 views
    0 likes
    Last Post PaulMohn  
    Working...
    X