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

trying to read write protected memory

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

    #16
    Hello neoikon,

    Thank you for your response.

    You should be able to pass a Stroke to a method. If you remove this logic do the errors continue?

    You can find our guide on setting up debugging in Visual Studio at the following link: https://ninjatrader.com/support/help..._debugging.htm

    Microsoft has a guide on Visual Studio debugging at the following link: https://msdn.microsoft.com/en-us/library/sc65sadd.aspx

    Comment


      #17
      It shouldn't really be a problem with VS. As a first try, open each of your indicators in NT and set them into Debug Mode. Click on the VS icon in the NT editor to launch VS, attach to process (your chart) in VS Debug tab, and add indicator to your chart. Do this one indicator at a time and see if it catches anything.

      Comment


        #18
        Originally posted by NinjaTrader_PatrickH View Post
        You should be able to pass a Stroke to a method. If you remove this logic do the errors continue?
        I haven't found anything to fix the issues, unfortuantely. I am just grasping at straws.

        Thanks for the links! I will check them out.

        Comment


          #19
          So here is my suggestion. It may not be the most efficient way to do this but if all else fails I suck it up and resort to the brute force approach.

          Create a test chart. The load only 1 of your indicators.Take the first indicator you have and place several Print statements throughout it. Label each print statement with your indicator name; for example, Print("Indicator 1"). In your second indicator use Print("Indicator 2") and so on. Load your indicators on a chart and run it. Hopefully this will let you isolate the problematic indicator.

          Comment


            #20
            For anyone who finds this later on, one of the things that tech support had me do is go through and update all my drivers. I used a free app called "Driver Booster" (and a supplemental app called "Advanced SystemCare" by the same company), which did the trick very painlessly.

            That aside, there may be some validity to passing a "new Stroke()" to a function being problematic.

            If I do the following, then I'm never explicitly setting the RenderTarget on that new Stroke object that's being created and passed in. I would think it would always throw an error and not just randomly, but perhaps it is a multi-threading situation?
            PHP Code:
            MyFunction(new Stroke(myBrush)); 
            If I do the following, then it will immediately throw an OnRender error (as expected) regarding "attempted to read or write proteted memory". As it should, since RenderTarget is null on the new Stroke object.

            PHP Code:
            Stroke myStroke = new Stroke(myBrush);
            MyFunction(myStroke); 
            However, this should always be safe (obviously, all of these examples assume myBrush is not null).

            PHP Code:
            Stroke myStroke = new Stroke(myBrush);
            myStroke.RenderTarget RenderTarget;
            MyFunction(myStroke); 
            Because I can't reliably reproduce what I've been seeing within my code, I am still grasping at straws. But I'm hoping that it may help myself... and anyone who finds this, as something to try.
            Last edited by neoikon; 06-21-2018, 03:38 PM.

            Comment


              #21
              Hi neoikon,

              Let me preface this by saying that I do not know what your code does, and why you would need to pass a stroke in the manner you indicated. I am sure you have good reasons. However, here are a few thoughts...

              1. For efficiency, the stroke render target should be updated inside OnRenderTargetChanged(). So if you are calling your function from inside OnRender() this issue shouldn't even arise.

              2. Are you trying to call your function from outside OnRender()? If yes, here you may have issues as RenderTarget is not readily available. We have asked NT to make it available but so far nothing has been done in this direction to my knowledge.

              3. This type of intermittent issue might be indicative of a coding architecture or logic issue, and may be suggesting a rewrite of the manner in which this function is being accessed.

              Just a few thoughts. Hope this helps.

              Comment


                #22
                Originally posted by neoikon View Post
                There seem to be 3 situations/errors that I've seen

                PHP Code:
                2018-06-12 09:03:27:352 ERRORIndicator ''Error on calling 'OnRender' method on bar 1507Attempted to read or write protected memoryThis is often an indication that other memory is corrupt
                PHP Code:
                2018-06-15 10:36:47:964 ERRORIndicator ''Error on calling 'OnRender' method on bar 1512External component has thrown an exception
                Or there is no error at all and NinjaTrader just crashes. Hitting "debug" shows the error:

                PHP Code:
                Unhandled exception at 0x00007FF82724842B (ntdll.dllin NinjaTrader.exe0xC0000374A heap has been corrupted (parameters0x00007FF8272AC6E0). 
                They all seem "corrupted memory" related.

                NT Tech support suggested running "netsh winsock reset" from a command line, which didn't seem to do anything for my situation, but perhaps it can help others.

                Any help in trying to isolate where this error could be coming from or any steps on how to debug/use an external debug tool, etc is greatly appreciated!

                Thank you
                Some suggestions:
                • Encase your code in a try...catch block and examine the Exception message.
                • When using Print() statements to debug, include the indicator name in the Print() output.

                Comment


                  #23
                  Originally posted by koganam View Post
                  Some suggestions:
                  • Encase your code in a try...catch block and examine the Exception message.
                  • When using Print() statements to debug, include the indicator name in the Print() output.
                  Thank you for the reply. Regarding try/catch, I definitely use that often. Unfortunately, the exception doesn't get thrown at all and instead I get a "Attempted to read or write protected memory. This is often an indication that other memory is corrupt", if I get any error at all. After that, NinjaTrader freezes or otherwise becomes very unstable/unuseable.

                  The problem is the randomness of it. For example, I haven't had an issue in the past few days (with NT running for about 12 hours a day). Which makes me feel as if the issue is resolved, then a week later, it happens multiple times in one morning. *shrug*

                  Comment


                    #24
                    Hi neoikon, I am running into this exact same problem right now. I use a bunch of custom indicators and having this same error intermittently so it is very hard to know what is causing it. I am wondering if you were able to find a solution that you can share with me? Thanks.

                    Comment


                      #25
                      I really wish external indicators (anything not explicitly created/provided by NinjaTrader) were contained in a box to protect the stability platform itself. Some kind of protective layer that runs independent of the core platform that can completely crash and burn, but not bring down the functionality of the platform.

                      Any joe blow can create a janky indicator and bring down the entire platform. Then, it becomes a support headache for me, as a content creator, when I need to determine if the issue is caused by something I wrote or one of the thousand other indicators they have on their machine.

                      Unfortunately, 4 years later, kv712 I never found a solution to the original problem above.
                      Last edited by neoikon; 05-12-2022, 10:52 PM.

                      Comment


                        #26
                        neoikon Thank you for replying. Do you think this could be caused by chart template file being corrupted? I am still testing it but I don't have this issue when I have created my charts from scratch and once I start using it and start making minor changes and save it over then the issues starts to surface again.

                        Comment


                          #27
                          Hello kv712 and neoikon,

                          Thanks for your note.

                          You would need to follow a procedure that could eventually reproduce the symptom so you can narrow things down to determine where the issue is coming from.

                          Something to consider is eliminating components in groups which can be faster than eliminating components one by one. From there, you could inform the author of where the issue is coming from and the exact steps to reproduce the issue.

                          If there are not any clues as to what is causing the error, the script can be reduced to find the problematic part.

                          Reducing:
                          When working with any issue, it is important to take steps to isolate the issue so that the exact line causing the behavior can be found. This is a process of elimination and a process of debugging by adding prints.

                          First, its great to create a copy of the script so that the original work is kept safe. Below is a link to a video that demonstrates making a copy of the script. Once the copy is created, the copy can be modified in any way without losing the original work.
                          https://www.youtube.com/watch?v=BA0W...utu.be&t=8m15s

                          The next step is to start commenting out code. Its helpful to think about when the error is occurring to target areas, and comment code from everywhere else quickly. If at any point after removing some code, the error stops, add the last removed item back.

                          If the error is occurring while the script is loading, the issue is likely somewhere in OnStateChange(). In this situation its best to remove any logic in OnBarUpdate, remove any custom methods and classes, and remove as may properties as possible, while still being able to reproduce the error.

                          If the error is occurring when saving a template, the issue is likely with a private or public variable declaration. First, remove all logic leaving the variable declarations behind. (Empty State.Configure, State.Dataloaded, State.Historical, OnBarUpdate, OnMarketData, and remove any custom methods.) Then start removing the variables one by one and testing until the error stops. When the error stops add the last removed item back. Ensure that this item is private or property serialized or using the Browsable(false) attribute. (More about the Browsable attribute below)

                          If the error only occurs while the strategy is trading, this is likely a run time method. For this its best to use prints to understand the behavior.

                          Note that often times these types of errors are related to scripts that perform custom rendering.

                          Let us know if we may assist further/
                          Brandon H.NinjaTrader Customer Service

                          Comment


                            #28
                            I've even had support connect to my machine and still no luck in finding the instability. I will say that when you connect/disconnect multiple data feeds within NinjaTrader, things get MUCH less stable. Often the feed just completely stops, etc.

                            My solution has been to simply use NinjaTrader less.

                            Thanks for the reply Brandon, but there is no error. There is nothing to isolate. No messages in the logs/trace files. No memory leaks (NT not becoming huge in the task manager). No repeatable way to reproduce the problem. It's just complete instability of the platform. Charts locking up or freezing. Data feeds stopping (including Kinetick). General unresponsiveness.

                            Comment


                              #29
                              Hello neoikon,

                              Thanks for your note.

                              Does the behavior happen if you open NinjaTrader in Safe Mode?

                              Safe Mode will prevent NinjaTrader from:
                              • Loading workspaces.
                              • Connecting on start-up.
                              • Loading custom assemblies.
                              • Getting instrument updates from the server.
                              To enable safe mode, please use the following steps:
                              • Exit NinjaTrader.
                              • Hold the CONTROL key and double click the NinjaTrader icon.
                              • Keep the CONTROL key held down until you see the Control Center.
                              • You can verify you are in safe mode by going to Help -> About.
                              Also, see this help guide documentation about using third-party AddOns: https://ninjatrader.com/support/help...tallingAdd-Ons

                              Let us know if we may assist further.
                              Brandon H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by mmenigma, Today, 02:22 PM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by frankthearm, Today, 09:08 AM
                              9 responses
                              35 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by NRITV, Today, 01:15 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post NRITV
                              by NRITV
                               
                              Started by maybeimnotrader, Yesterday, 05:46 PM
                              5 responses
                              26 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by quantismo, Yesterday, 05:13 PM
                              2 responses
                              21 views
                              0 likes
                              Last Post quantismo  
                              Working...
                              X