Announcement

Collapse
No announcement yet.

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.

    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

        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:

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            581 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            338 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
            554 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