Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ERROR: Failed to call OnRender() External component has thrown an exception

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

    ERROR: Failed to call OnRender() External component has thrown an exception

    Hi All,

    The attached drawing object is a copy of the 'Ruler.cs' which has several modifications. The lines which keep failing are original code lines that were not modified which makes the problem stranger. It is not easy to replicate, it seems to me that as the number of Altline objects increases and the number of bars on the chart accumulate the quicker the error will appear. So in faster markets when there are more Altline objects on the chart the error will happen quicker.

    The example below is the most common point of error but there are others but always on a rendertarget statement. The other strange thing is that I could not replicate the problem if in debug mode with visual studio. I believe the line in the example below is 386.

    Using Ninja 8.0.22.2 x64


    Trace error:
    2020-10-28 20:37:24:881 ChartObject.Render.ERROR: Render exception on non finalized chart object 'NinjaTrader.NinjaScript.DrawingTools.Customized.A ltRuler' System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
    at SharpDX.Direct2D1.RenderTarget.DrawRectangle(Recta ngleF rect, Brush brush, Single strokeWidth, StrokeStyle strokeStyle)
    at NinjaTrader.NinjaScript.DrawingTools.Customized.Al tRuler.OnRender(ChartControl chartControl, ChartScale chartScale)
    at NinjaTrader.Gui.Chart.ChartObject.Render(RenderTar get renderTarget, ChartControl chartControl, ChartScale chartScale)
    2020-10-28 20:37:24:883 ERROR: Indicator '': Error on calling 'OnRender' method on bar 3410483: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
    2020-10-28 20:39:58:869 ERROR: Connection lost to the NinjaTrader Historical Data Server: hds-us-nt-001.ninjatrader.com
    2020-10-28 20:40:40:886 Server.HdsClient.Connect: type=HDS server='hds-us-nt-003.ninjatrader.com' port=31655 system='' useSsl=True


    AltRuler.cs

    trace.txt
    Attached Files
    Last edited by Bidder; 10-29-2020, 12:03 AM.

    #2
    Hello Bidder,

    Thank you for the post.

    I took a quick look at the file however it is very different from the existing ruler tool so it would be difficult for me to see what may be causing the issue from a comparison between the two.

    When you say its not easy to replicate, what steps are you taking to produce the error? Is it on the chart for a while or is there a threshold of the amount of objects needed?

    Finding a way to cause the error will be one of the first debugging steps so you can then explore the changes you made further. If the original tool does not throw the error in the same use case that will help to isolate the problem is with the changes you made. If this relates to the number of objects you can try using the Playback connection to quickly move through a period of time or you could also try and make a test using an Indicator to just draw your object many times quickly.

    Looking at the error it mentions DrawRectangle, there is only 1 DrawRectangle in the script so that would be a good place to start reviewing your changes. Do you use any of the variables the DrawRectangle used in your changes or are you modifying values of anything DrawRectangle uses? That could help trace back into your modifications to better understand the error.

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

    Comment


      #3

      What I was hoping from for a first response is not necessarily to have the problem immediately duplicated on your test system but maybe some general principles about render errors and possible areas for me to refine my debugging efforts. For example, this morning the application blew up with less than 10 objects being on the chart and in less than 15 minutes. I set the project to compile in debug mode, recompiled, restarted NT then proceeded to add over 100 objects and it has been running for hours without issue. How can that be?? The answer to that question may be a step toward a final resolution.

      Or possibly some general information on what the error "SEHException (0x80004005): External component has thrown an exception" means.

      Anyway, to answer your questions:


      I took a quick look at the file however it is very different from the existing ruler tool so it would be difficult for me to see what may be causing the issue from a comparison between the two.
      Ok. so to clarify, the code is in a different order yes, but is almost identical to the original in the areas where the errors are originating. Looking deeper it can be seen that the Onrender from AltRuler.cs and the Onrender from Ruler.cs are 100% identical except for the very first line that calls the Renderfibs routine. The Renderfibs routine is almost identical to the original Onrender routine from the FibonacciTools.cs in class FibonacciRetracements. These two areas are where the errors seem to be originating from.


      When you say its not easy to replicate, what steps are you taking to produce the error? Is it on the chart for a while or is there a threshold of the amount of objects needed?
      Add objects to the chart. The more there are will cause the error to happen sooner. I have included the defaults xml file. The way I am using it will have properties "Short price" and/or "Show fibonacci lines" checked.



      Default.zip

      Comment


        #4
        After setting the csproj in debug mode and recompiling and adding all these lines the application has been running for hours.

        As an experiment, I removed debug mode recompiled and then refreshed the pictured chart with all the lines still attached and the entire application crashed in less than a minute.

        Code:
        2020-10-29 09:09:02:704 ERROR: Failed to call OnRender() for chart object 'Alt Ruler': 'External component has thrown an exception.'
        2020-10-29 09:09:02:705 ChartObject.Render.ERROR: Render exception on non finalized chart object 'NinjaTrader.NinjaScript.DrawingTools.Customized.A ltRulerFib' System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception.
        at SharpDX.Direct2D1.RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush, Single strokeWidth, StrokeStyle strokeStyle)
        at NinjaTrader.NinjaScript.DrawingTools.Customized.Al tRulerFib.RenderFibs(ChartControl chartControl, ChartScale chartScale)
        at NinjaTrader.NinjaScript.DrawingTools.Customized.Al tRulerFib.OnRender(ChartControl chartControl, ChartScale chartScale)
        at NinjaTrader.Gui.Chart.ChartObject.Render(RenderTar get renderTarget, ChartControl chartControl, ChartScale chartScale)
        2020-10-29 09:09:02:709 ERROR: Failed to call OnRender() for chart object 'Alt Ruler': 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
        2020-10-29 09:09:02:709 ChartObject.Render.ERROR: Render exception on non finalized chart object 'NinjaTrader.NinjaScript.DrawingTools.Customized.A ltRulerFib' System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
        at SharpDX.Direct2D1.RenderTarget.DrawTextLayout(Vect or2 origin, TextLayout textLayout, Brush defaultForegroundBrush, DrawTextOptions options)
        at NinjaTrader.NinjaScript.DrawingTools.Customized.Al tRulerFib.OnRender(ChartControl chartControl, ChartScale chartScale)
        at NinjaTrader.Gui.Chart.ChartObject.Render(RenderTar get renderTarget, ChartControl chartControl, ChartScale chartScale)
        2020-10-29 09:09:02:709 ERROR: Failed to call OnRender() for chart object 'Alt Ruler': 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
        2020-10-29 09:09:02:709 ChartObject.Render.ERROR: Render exception on non finalized chart object 'NinjaTrader.NinjaScript.DrawingTools.Customized.A ltRulerFib' System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
        at SharpDX.Direct2D1.RenderTarget.DrawLine(Vector2 point0, Vector2 point1, Brush brush, Single strokeWidth, StrokeStyle strokeStyle)
        at NinjaTrader.NinjaScript.DrawingTools.Customized.Al tRulerFib.RenderFibs(ChartControl chartControl, ChartScale chartScale)
        at NinjaTrader.NinjaScript.DrawingTools.Customized.Al tRulerFib.OnRender(ChartControl chartControl, ChartScale chartScale)
        at NinjaTrader.Gui.Chart.ChartObject.Render(RenderTar get renderTarget, ChartControl chartControl, ChartScale chartScale)
        Last edited by Bidder; 10-29-2020, 09:16 AM.

        Comment


          #5
          Hello Bidder,


          Or possibly some general information on what the error "SEHException (0x80004005): External component has thrown an exception" means.
          This error simply means something external that's not C# caused an error. NinjaTrader uses SharpDX for rendering which uses directx. The error is not going to be very helpful because there are no details on what made that error so debugging the code is the best bet.


          Looking deeper it can be seen that the Onrender from AltRuler.cs and the Onrender from Ruler.cs are 100% identical except for the very first line that calls the Renderfibs routine. The Renderfibs routine is almost identical to the original Onrender routine from the FibonacciTools.cs in class FibonacciRetracements. These two areas are where the errors seem to be originating from.
          You could try commenting out that modification and return to the original OnRender to confirm if that's related or not. This could also relate to your other logic if any of the properties used in OnRender are being modified or changed in other ways than the default tool.



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

          Comment


            #6
            This error simply means something external that's not C# caused an error. NinjaTrader uses SharpDX for rendering which uses directx. The error is not going to be very helpful because there are no details on what made that error so debugging the code is the best bet.
            Mention was made several times that the error does not happen in Debug mode.


            You could try commenting out that modification and return to the original OnRender to confirm if that's related or not. This could also relate to your other logic if any of the properties used in OnRender are being modified or changed in other ways than the default tool.
            That has in effect already been done. When "Show fibonacci lines" is unchecked the routine does not get called making the OnRender identical to the original.





            Comment


              #7
              Hello Bidder,
              Mention was made several times that the error does not happen in Debug mode.
              I would suggest to leave debug mode off so you can trace where the issue is happening in the modifications. When we mention that you need to debug your code that means to go through it and check it, I did not mean to use visual studio or its debugging tools. OnRender errors or sharpdx errors generally can't be reviewed in visual studio because the source code is not present for where the error was generated, that error happens in the external directx libraries.

              That has in effect already been done. When "Show fibonacci lines" is unchecked the routine does not get called making the OnRender identical to the original.
              Did it begin working when you did that or did it still have problems?
              The purpose of making the OnRender the same would be to check if the changes to the rendering code is related. If that change is not related you could move to the other modifications you made to verify those are or are not related.


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

              Comment


                #8
                Hi Jesse,

                Would you be able to give me some idea of what is going on under the hood when "Debug mode" is turned on during the compile ?


                Click image for larger version

Name:	db.png
Views:	605
Size:	17.7 KB
ID:	1126265

                Comment


                  #9
                  Hello Bidder,

                  This is Jim, responding on behalf of Jesse who is out of the office at this time.

                  You can read more about debug builds and release builds for software development here (publicly available resource) - https://stackoverflow.com/questions/...rence-and-uses

                  Debug builds generally do not have compile time optimizations in place, and they also have debug symbols which allows you to hook up a debugger and use breakpoints.

                  You would check Debug Mode in NinjaTrader if you wanted to attach Visual Studio's debugger.

                  Debugging with Visual Studio - https://ninjatrader.com/support/help..._debugging.htm

                  We look forward to assisting.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    What kind of error trapping can be done in ninjascript to prevent the entire application from crashing when there is an OnRender error?


                    OnRender errors or sharpdx errors generally can't be reviewed in visual studio because the source code is not present for where the error was generated, that error happens in the external directx libraries.

                    Comment


                      #11
                      Hello Bidder,

                      For SharpDX errors there is really no way to trap that, you just need to look through your code to figure out what code you are using which is causing the problem.

                      Without knowing what specific code is responsible or how it was used when it had an error I couldn't really suggest any type of solution other than review the code and make sure it all is valid. You can try commenting out some of your added code and then try to produce the error to see if that part of the code is related as a debugging step. If you can see this using the standard tool with no modifications then I would just need the steps you used to reproduce the error.


                      I look forward to being of further assistance.

                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Bidder was there a resolution on this?

                        Comment


                          #13

                          In the SharpDX SDK Reference there is a best practices section.
                          I found some code in a custom draw tool that was doing the following. Made the change and the problems stopped.

                          Click image for larger version

Name:	20230527_222026_WS2.png
Views:	200
Size:	10.8 KB
ID:	1253367
                          Attached Files

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by DJ888, 04-16-2024, 06:09 PM
                          4 responses
                          11 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by terofs, Today, 04:18 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post terofs
                          by terofs
                           
                          Started by nandhumca, Today, 03:41 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post nandhumca  
                          Started by The_Sec, Today, 03:37 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post The_Sec
                          by The_Sec
                           
                          Started by GwFutures1988, Today, 02:48 PM
                          1 response
                          9 views
                          0 likes
                          Last Post NinjaTrader_Clayton  
                          Working...
                          X