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

Gradient Brush problem - Attempted to read or write protected memory

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

    Gradient Brush problem - Attempted to read or write protected memory

    I have similar issue as described: https://ninjatrader.com/support/foru...otected-memory

    I use these 2 methods to write GradientBrush and FillGeometry in OnRender

    Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.



    and the code I have in indicator:


    OnRender()...

    Code:
    SharpDX.Direct2D1.Brush brush2 = null;
    
    try
    {
        if (chartControl == null || RenderTarget==null || ChartBars==null || chartScale==null)
            return;
    
        Brush curBrush = Brushes.Blue;
        float x= ...;
        brush2 =BrushToGradient(RenderTarget, curBrush, 100, curBrush, 20, x, x, x, x);
        fillGeometry(RenderTarget, brush2, vector1, new[] { vector2,vector3,vetor4 });
    }
    catch(Exception e)
    {
       Print(e.ToString());
    }
    finally
    {
        if (brush2 != null) brush2.Dispose();
    }
    however, After running on 2-3 hours the indicator throws the error:
    Error on calling "OnRender"...

    My Question: is that a problem that I call Methods for creation those things? What should I do to avoid the problem?
    Last edited by ttodua; 11-22-2019, 04:44 AM.

    #2
    Hi ttodua, thanks for your post.

    It looks like the problem might be coming from fillGeometry(RenderTarget, brush2, vector1, new[] { vector2,vector3,vetor4 });. This method needs to be ran from the RenderTarget object. I recommend making two test scripts, one that implements the GradientBrush and another that implements the FillGeometry. See which one works and which one fails. There are also examples on the FillGeometry in many of the drawing tools, the Polygon tool uses one.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Chris, Many thanks...
      as problem happens after hours of running the indicator, it's very hard for me to debug the problem (even, the problem happens to my client, not on my platform).

      can you give me a hint, why my "fillgeometry" method might be failing? it is being called from OnRender, when the RenderTarget is not empty/null.
      also, in that method, the Disposable objects are being disposed too.
      so, what's wrong with that method, please any hint?

      Comment


        #4
        Hi ttodua, thanks for your reply.

        The Polygon tool is calling FillGeometry like so: RenderTarget.FillGeometry(...) Please try it this way. I would also be happy to test a reduced sample if you can post one.

        Kind regards,

        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          sorry , i think i dont fully understand because my code (sample on link i provided on pastebin) has that:

          public static void fillGeometry(SharpDX.Direct2D1.RenderTarget renderTarget..........)
          ...
          renderTarget.FillGeometry(geo1, dxBrush);


          well, i think i will pause on this problem for a while and will return investigation later. if i will see more problems will post the reduced indi. just i cant understand with the infromation i say, why that makes problem.

          Comment


            #6
            Hi ttodua, thanks for your reply.

            Since you mentioned this does not happen on your machine the client might need to first ensure they have the latest graphics drivers installed as well as turning off power saving for PCI slots.

            See here for a guide on doing this:

            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            22 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X