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

ToDxBrush crashing or freezing - Possible Bug Report

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

    ToDxBrush crashing or freezing - Possible Bug Report

    Hi:

    When creating a radialgradient brush in SharpDX I receive this error message and the indicator stops rendering


    Error al llamar ' OnRender' método en barra 27612: Intento de leer o escribir en la memoria protegida. A menudo, esto indica que hay otra memoria dañada.


    It translates to "Attempt to read or write protected memory. This usually means there is some other damaged memory."


    This is what appears to be an access violation and likely happening in unmanaged code.

    Makes me think there is a bug in NinjaTrader or SharpDX


    This is what I am doing (rgb is radialgradient brush)

    Code:
    for( ; ; )
    {
    
    ... radial gradient brush created
    
      try
      {
        SharpDX.Direct2D1.Brush lgbdx = rgb.ToDxBrush(RenderTarget);
    
        ... FillEllipse here
    
        lgbdx.Dispose();
      }
      catch (System.AccessViolationException sve)
      {
        // got internal bug exception <--- sometimes this doesn't catch it
      }
    }
    This loop could run thousands of times in a single OnRender call

    As a side note I was getting ToDxBrush freezing sometimes with lineargradient brush but only if executed many times. If done only a few times it works fine. Seems something is fishy there.

    Latest NinjaTrader version (8.0.23.1 - 64 bits) but with previous was getting that too.

    Regards
    Waldo
    Last edited by waldoalvarez; 12-04-2020, 05:15 AM.

    #2
    Hello waldoalvarez,

    Thanks for the post.

    From the given details I couldn't really say that there is any kind of bug, are you certain that all values being used in the creation of the brush are valid?

    You mentioned that the loop runs thousands of times so that leaves a lot of code being run which could have problems. Do you see this at all if you don't use the loop and instead create 1 brush in the same location? If the loop is required, do you see if you create the same brush over and over? That would just be so we know a valid brush is being used every iteration, instead of making a dynamic brush just use a standard brush and ToDxBrush().

    This is likely a situation where you would need to further isolate what is happening by reviewing the details of what is being done at the time of the error. If the loop is required you may need to try and output the values by using the try/catch if it picks up the exception, if that won't pick up the exception you may need to just try and reduce the loop to find what is causing the error. Trying to isolate the steps used to produce the error will also be helpful. You may want to try actions which cause a render target change like maximizing the window or dragging it around/resizing it.

    One possibility is that if the loop is running too long the render target being used could no longer be valid in certain cases. Using OnRenderTargetChanged is generally where brush creation is done to create a cache of brushes to reuse. If the loop is calculating the same brushes every iteration you may want to look into using a cache for efficiency here.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi:

      I filtered for all negatives values in brushes creation etc. Radius, position (position should be ok but still). I also froze the System brushes. It takes a long time to crash (stability seems improves) but I still get it. I added some more exceptions to capture even "Exception" with a breakpoint in the catch block debugging with visual studio and It doesn't breaks at all. I did all of this with the debugger attached.

      I cannot create those brushes in OnRenderTargetChanged because there are so many brushes. I would have to implement some sort of LRU cache in that case because there are easily 60 thousand of them in a few days chart. This happens in 3 lines code and brushes are not reused across OnRender calls.

      I also had two charts opened and both crashed at aprox the same time. The trace file gives nothing new, same two lines of access violation for each chart.

      Looks like some resource is exhausted over time and eventually causes some access violation.

      It works fine with Regular Brushes and with less brushes it works ok too. The problem appears when many Radial Brushes are created.

      Comment


        #4
        I saw in Debug Output Window this:

        Exception thrown: 'System.AccessViolationException' in SharpDX.Direct2D1.dll

        Comment


          #5
          Hello waldoalvarez,

          Thank you for the reply.

          From the added information really all that sticks out is that you may be doing too much work from OnRender.
          I would have to implement some sort of LRU cache in that case because there are easily 60 thousand of them in a few days chart. This happens in 3 lines code and brushes are not reused across OnRender calls.
          You may need to do that, it is the general expectation that brushes will be reused and not re created on every render pass. Creating one brush on every render would be fine but it sounds like your use case would be better suited for some kind of cache to retain performance. OnRender is simply the rendering outlet, that is not usually a good choice for doing any calculation logic or creation logic. The purpose of OnRenderTargetChanged is to create or recreate all resources being used so you can have the correct render target when rendering. If what you are doing takes a long time in OnRender its possible the drawing will try to use the incorrect target or a disposed target.

          Were you able to do any tests involving the brush creation or the loop as I had mentioned in the last post? That is going to be a necessary step here to filter what the problem is, that or finding the series of events that causes the error to happen so you can test it.


          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by LawrenHom, Today, 10:45 PM
          0 responses
          3 views
          0 likes
          Last Post LawrenHom  
          Started by love2code2trade, Yesterday, 01:45 PM
          4 responses
          28 views
          0 likes
          Last Post love2code2trade  
          Started by funk10101, Today, 09:43 PM
          0 responses
          7 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          37 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          44 views
          0 likes
          Last Post bill2023  
          Working...
          X