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

Chart rendering failed-same factory instance

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

    Chart rendering failed-same factory instance

    Hello-

    Yesterday, one hour before close, I got the following error I have never seen before which crashed NT8:

    2017-03-27 13:50:34:735 ERROR: Indicator 'ncatOrderFlow': Error on calling 'OnRender' method on bar 125: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

    ncat is a 3rd party indicator with locked code. It has been running since late last year with no problems, until yesterday. I did a RAM test on my system showing no problems.

    Today, I got the following error I have never seen before, which happened twice. No crashing occurred:

    2017-03-28 14:34:46:118 ERROR: A direct X error has occurred while rendering the chart: HRESULT: [0x88990012], Module: [SharpDX.Direct2D1], ApiCode: [D2DERR_WRONG_FACTORY/WrongFactory], Message: Objects used together must be created from the same factory instance.
    2017-03-28 14:34:46:118 ERROR: Chart rendering failed. There is likely a problem with a chart object's OnRender method. D2D error = 'HRESULT: [0x88990012], Module: [SharpDX.Direct2D1], ApiCode: [D2DERR_WRONG_FACTORY/WrongFactory], Message: Objects used together must be created from the same factory instance. '

    All indicators running today were identical to the indicators running yesterday.

    Could someone give me an idea of what causes these errors and some guidance as to how to solve them?

    W10, 64bit, 10gbRAM, NT 8.0.5.2.

    Thank you.

    #2
    Hello imalil,

    Thank you for your post.

    Please send me your log and trace files so that I may look into what occurred.

    You can do this by going to the Control Center-> Help-> Email Support.

    Please list 'ATTN: Patrick H' in the subject line and reference this thread in the body of the email.

    I look forward to your response.

    Comment


      #3
      Could this statement: "Objects used together must be created from the same factory instance" come about from an incorrect use of IF, ELSE IF statements?

      What exactly is this statement saying?

      Comment


        #4
        Hello imali,

        Thank you for your response.

        That message is a bit vague. If you send over the Log and Trace files we could look into this and the other messages further.

        Comment


          #5
          I noticed on my IF, ELSE IF statements I did not end them with an ELSE statement. I put in the ELSE statements and I did not get an error today.

          Does this make sense to you?

          Thank you.

          Comment


            #6
            Hello imalil,

            Thank you for your post.

            In a generic case, no, this does not make sense. However, it would depend on the functions being performed in the if else.

            Please let me know if you have any questions.

            Comment


              #7
              I ran my multiple chart workspace all day--I did not watch it. I returned, everything had run fine. Then I maximized one of my charts and NT8 crashed before I had a chance to screenshot my Level 2 data.

              The error:

              "2017-04-05 15:33:31:725 ERROR: Indicator '': Error on calling 'OnRender' method on bar 785: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
              2017-04-05 15:33:31:732 ERROR: Failed to call OnRender() for chart object 'Text': 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'"

              Many of these occurred in a row, all at the same time, in the log/trace.

              I'm sure you'll ask for log/trace, but I have one question first:

              Can you confirm you have seen this issue with other users?

              Thanks.

              Comment


                #8
                Hello imalil,

                Thank you for your response.

                These errors have been seen in other cases. However, the cause has differed across the cases.

                The Log and Trace will allow us to get a better picture of what is occurring.
                2017-04-05 15:33:31:725 ERROR: Indicator '': Error on calling 'OnRender' method on bar 785: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
                2017-04-05 15:33:31:732 ERROR: Failed to call OnRender() for chart object 'Text': 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
                This could indicate memory is not available and that the Garbage Collection needs to run for .NET. Generally restarting the platform should correct this.


                I look forward to your response.

                Comment


                  #9
                  This answer makes sense.

                  Thanks.

                  Comment


                    #10
                    Objects used together must be created from the same factory instance

                    Hi,
                    I am needing some assistance with avoiding this OnRender exception. It is not occurring on my computer (frustratingly) but on customers' computers.
                    As far as I can see the code is built as per recommendations with instances of DX brushes being created either on-the-fly within OnRender or within OnRenderTargetChanged().

                    For example,

                    Code:
                    		public override void OnRenderTargetChanged()
                    		{
                    			// move all setting to here
                    			DisposeOfGraphicsResources();	// dispose first
                    			if (RenderTarget==null || ChartControl==null)
                    				return;
                    			
                    			upBrushDX = Color_Up.ToDxBrush(RenderTarget);
                    			downBrushDX = Color_Down.ToDxBrush(RenderTarget);
                    			zeroBrushDX = Color_Zero.ToDxBrush(RenderTarget);
                    			extremeBrushDX = Color_ExtremeValue.ToDxBrush(RenderTarget);
                    			
                    		}
                    or within OnRender itself:

                    Code:
                    SharpDX.Direct2D1.Brush axisBrushDX = axisPen.Brush.ToDxBrush(RenderTarget);
                    I have a question about a TextLayout I am using to draw some text. It is generated on-the-fly in OnRender() and is based on a DirectWriteFactory in Ninja.Core.Globals. Can this factory instance change, and thus produce this "not the same factory instance" problem?

                    Code:
                    TextLayout textLayout = new TextLayout(NinjaTrader.Core.Globals.DirectWriteFactory, s, textFormat, width*1.33f, textFormat.FontSize);
                    						textLayout.TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading;
                    						RenderTarget.DrawTextLayout(new SharpDX.Vector2((float)x - width/2f,(float)y), textLayout, 
                    												(pctVal == 0 ? zeroBrushDX : (Math.Abs(pctVal) >= ExtremeValue ? extremeBrushDX : (directionSeries.GetValueAt(currentbar) ? upBrushDX : downBrushDX)))
                    												);
                    Any help you've got would be appreciated.
                    Cheers,
                    saltminer

                    Comment


                      #11
                      [bump] Please guys, it is driving everybody crazy.

                      Comment


                        #12
                        Hello saltminer,

                        I am currently using the code sample you provided to try to see the same thing on my end in a controlled environment.

                        I have attached the test script I am using. Please feel free to modify and return this script to us if it is missing anything vital to seeing the same thing on our end that you are seeing on yours. If any proprietary modifications are made they may be sent to platformsupport[at]ninjatrader[dot]com . You would then want to reference 1684197 and Attn:NinjaTrader_JessicaP in the subject line of your e-mail.

                        I will return shortly when I have more information.
                        Attached Files
                        Last edited by NinjaTrader_JessicaP; 04-12-2017, 12:21 PM.
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          I have some more information which may be useful. While I still have not been able to see the same thing on my end, I have found with respect to the factory message the following publicly available link :

                          I just recently found out about Win2D and I'm trying to get to grips with it. I'm trying to load an image file, process it somehow (e.g. draw some text on it) and use it to draw on screen. I asynch...


                          This suggests that the object mentioned is the context for a render target. I would like to suggest, as a step to reproduce this, that you experiment creating brushes during OnRenderTargetChanged, and using them outside of this method. It is my working theory that you are using a brush between when a render target has changed, and when your brush's dispose code is reached, asynchronously.

                          A recommend code pattern, should this be the cause, is to always create and dispose of brushes within the same method, rather than keeping SharpDX.Direct2D1.Brush references at the member level of your class. If you have access to a client's computer, and you are unable to see the same thing on your end, as a troubleshooting step I would recommend reducing every SharpDX.Direct2D1.Brush reference to method scope.
                          Jessica P.NinjaTrader Customer Service

                          Comment


                            #14
                            I was unable to see the same thing on our end that you were seeing on yours with the attached script. Please modify this script, or send us contact information discretely for a customer whose machine can reproduce this at platformsupport[at]ninjatrader[dot]com referencing Attn:NinjaTrader_JessicaP and 1684197 in the subject line of your e-mail.
                            Attached Files
                            Jessica P.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Jessica,
                              I have uploaded an enhanced version of your example that actually does things in OnRender, creating text and ellipses and thus using the TextLayout and DX Brush objects together.
                              Not sure if it will recreate the problem, but let's see.

                              Meanwhile, let me check I understand your instructions.
                              * I should create and use objects only within OnRender().
                              Is that correct?

                              To me that makes sense, but it is contrary to other advice in script examples and online guide which recommends the use of instances of a brush, set once, then reused in OnRender() to avoid the expensive Brush.ToDXBrush() method. There are also recommendations to use OnRenderTargetChanged() for this purpose.

                              Thanks,
                              saltminer.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jclose, Today, 09:37 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,414 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Today, 08:53 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post firefoxforum12  
                              Started by stafe, Today, 08:34 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by sastrades, 01-31-2024, 10:19 PM
                              11 responses
                              169 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X