Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Gradient throws External component exception

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

    Gradient throws External component exception

    Using RC1 on a Win7 64 machine:
    I modified a copy of @CandleStyle to replace the solid brush FillRectangle with a LinearGradientBrush fill. Using this GradientCandleStyle on a TickReplay chart often throws a fatal error, locking NT:
    System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
    So, I enclosed the modified code within try/catch. This changes the error somewhat:
    TROUBLE! GradientCandleStyle.OnRender External component has thrown an exception.
    I've attached a zip file with the code and two log files. Is there something I'm doing wrong?
    Attached Files

    #2
    Hello tradesmart, and thank you for your question. In order to help you track down what was occurring, I have added some additional logging code immediately before the code which locked your thread. If you review the output of this code, it should steer you in the correct direction. It may be beneficial to refactor your code so that you are initializing sdx_lgbrush completely before attempting to call FillRectangle. Please let us know if there are any other ways we can help.
    Attached Files
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      After adding your log code:
      First had to prepend NinjaTrader.Cbi to all the LogLevel.Information due to error 'System.LogLevel' is inaccessible due to its protection level.
      Then, after compiling, loading a workspace with a single chart using the GradientCandleStyle resulted in a hard crash:
      Problem signature:
      Problem Event Name: CLR20r3
      Problem Signature 01: NinjaTrader.exe
      Problem Signature 02: 8.0.0.13
      Problem Signature 03: 57c552c3
      Problem Signature 04: mscorlib
      Problem Signature 05: 4.0.30319.34209
      Problem Signature 06: 53489fcf
      Problem Signature 07: 378e
      Problem Signature 08: 44
      Problem Signature 09: FatalError
      OS Version: 6.1.7601.2.1.0.256.1
      Locale ID: 1033
      Additional Information 1: 594f
      Additional Information 2: 594f36fe22b44083bdf587f105863cb3
      Additional Information 3: 140b
      Additional Information 4: 140b1b4a3c9f9295f40ef8b6530960b5
      As you can see in the attached log file, it seems to have built 34 bars before throwing the External component exception.
      Then it built 5 more bars before returning to rebuild the first bar, repeating through all the bars, again and again until the crash.

      Restarting NT and opening the workspace does not cause the error. So, it's intermittent.

      The log file does not give me any reason that I can see.

      Please explain what you mean by "refactor your code so that you are initializing sdx_lgbrush completely before attempting to call FillRectangle".
      Attached Files

      Comment


        #4
        Steps to reproduce:
        (not connected to any data feed)
        1. Create a new TickReplay chart, e.g., ES 3 minute with built-in Candlestick style
        2. Change to GradientCandlestick style
        3. Add VolumeProfile indicator
        4. Add BuySellVolume indicator
        5. Save workspace
        6. Shut down NT8
        7. Restart NT8
        8. Load the saved workspace

        Comment


          #5
          Hello Tradesmart,

          Pulling all the DirectX code out of your sample produces a ChartStyle which does not crash Ninja with the procedure you outlined. This leads me to believe that your DirectX code is the code that needs to be modified to avoid the behavior we were seeing.

          By "refactor your code so that you are initializing sdx_lgbrush completely before attempting to call FillRectangle", I mean that you have a code block attached to a using declaration, and it is my opinion that if you take your call to FillRectangle out of that block and place it later in your code - while still making sure that everything you need survives the scope of the using declaration - that this will shine more light on what is happening and potentially resolve your query. At the very least, such a refactor will allow you two breakpoints in your code where you can at least put Print statements in, which should lead to a solution.

          Please let us know if there are any other ways we can help.
          Jessica P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_JessicaP View Post
            By "refactor your code so that you are initializing sdx_lgbrush completely before attempting to call FillRectangle", I mean that you have a code block attached to a using declaration, and it is my opinion that if you take your call to FillRectangle out of that block and place it later in your code - while still making sure that everything you need survives the scope of the using declaration - that this will shine more light on what is happening and potentially resolve your query. At the very least, such a refactor will allow you two breakpoints in your code where you can at least put Print statements in, which should lead to a solution.
            Thanks for the suggestion. In the interim, I have removed the using declaration in favor of simply declaring SharpDX.Direct2D1.LinearGradientBrush sdx_lgbrush. This seems to have improved stability significantly. This does mean, however, that sdx_lgbrush is not being disposed.

            I notice that in your @CandleStyle code, you declare Brush brush = closeValue >= openValue ? UpBrushDX : DownBrushDX; and do not perform brush.Dispose(). So, perhaps ChartStyles do automatic garbage collection making Dispose() and/or using() unnecessary? Can you confirm this?

            Comment


              #7
              I am glad that we were able to improve the stability. We have in fact made several changes to how Ninja manages memory recently, especially with regard to our Dispose routines. I am reviewing those now and will return shortly with my findings.
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                Hello again tradesmart,

                While there are objects that are not cleaned up - see LineOnClose and Mountain styles' source - it appears from the documentation for UpBrushDX and DownBrushDX that these do not need to be cleaned up.



                In addition, the release notes for RC1 state "The Stroke object .Dispose() method was removed due to technical redundancy. To remove memory resources from any stroke objects, simply set the stroke to null" .

                It appears the objects that are being cleaned up under ChartStyles are user created SharpDX objects, such as LineOnClose's SharpDX.Direct2D1.PathGeometry lineGeometry object or Mountain's SharpDX.Direct2D1.SolidColorBrush fillOutline object.

                Finally, the examples for ChartStyles in the documentation do not contain a Dispose call in OnTerminated the way e.g. PriceLevelContainers do in source.



                Therefore you should be safe if you avoid calls to Dispose except with regard to DirectX objects you create.

                Please let us know if there are any other ways we can help.
                Jessica P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Sparkyboy, Today, 10:57 AM
                0 responses
                1 view
                0 likes
                Last Post Sparkyboy  
                Started by TheMarlin801, 10-13-2020, 01:40 AM
                21 responses
                3,916 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by timmbbo, 07-05-2023, 10:21 PM
                3 responses
                152 views
                0 likes
                Last Post grayfrog  
                Started by Lumbeezl, 01-11-2022, 06:50 PM
                30 responses
                810 views
                1 like
                Last Post grayfrog  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                3 responses
                11 views
                0 likes
                Last Post NinjaTrader_Erick  
                Working...
                X