CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2010
    Posts
    47

    Question Solving "RangeChecks instrumentation code detected an out of range array access"

    Firstly, I am using Visual Studio 2013

    I have a project written in VB6 and VC++ 6.0 which I am porting over to VB.NET and VC++.

    Right at the heart of everything is a routine written in VC++ which runs to 1,400 lines of native code and processes a whole raft of arrays which are transferred from VB.NET. This routine may run for days during which time it literally runs through trillions of times (ie 10 ^ 12 ). If I split it into smaller routines there is a huge time penalty. Been there - tried that.

    Amazingly, I have got this working in principle (I had expected to spend months debugging it but it worked almost immediately). One of the problems is/was that if you referred to a VB6 array in VC++ 6.0 you have to reverse it - so, for example

    Code:
    ' VB6
    Public dblObjectArrayGP(OBJECTS_MAX, PROPERTIES_MAX, TRIALS_MAX, STEPS_MAX) As Double
    
    'In VC++ 6.0 refer to it as
    dblObjectArrayGP[][TRIALS_MAX + 1][PROPERTIES_MAX + 1][OBJECTS_MAX + 1];
    But it worked. Now in VB.NET - VC++ , Microsoft have arranged things so that you do NOT have to reverse arrays anymore. Which means that I have had to to reverse hundreds of array references (the law of unintended consequences). Hence my amazement when it worked in principle.

    I have spelled all this out because I know that people will reply along the lines of:
    "Why not write it all in VB.NET?"
    "Why not break it into many smaller routines?"
    "You should use Vectors not arrays" etc etc

    and that is not helpful - this is a conversion job not a new project (if it were I would do lots of things differently). The original was written over 25 years and is at the limits of my ability to hold it together (ie it is hideously complicated). Original version(s) were written in QB4.5 and Quick C.

    Now, when it runs maybe 50 times or so it fails and I get this message:

    "Unhandled exception at 0x77B76767 (SafariPark.dll) in MOPEKS.exe: RangeChecks instrumentation code detected an out of range array access"

    So, How do I find out which of my literally hundreds of array refences is causing this problem?

    I have tried

    Code:
    try{
    
    // Code here
    
    }
    
    catch(...){
    
    // Breakpoint here
    }
    but it does not seem to get there, instead it stops in Microsoft Code as per this:

    Code:
    #if defined (_M_IX86)
        volatile ULONG dw[(sizeof(CONTEXT) + sizeof(EXCEPTION_RECORD))/sizeof(ULONG)];
    #endif  /* defined (_M_IX86) */
    
    #if defined (_M_IX86) || defined (_M_X64)
        if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
    #endif  /* defined (_M_IX86) || defined (_M_X64) */
            __fastfail(FailureCode);
    
    #if defined (_M_IX86) || defined (_M_X64)
    All help much appreciated!
    Last edited by wavering; November 11th, 2014 at 07:02 AM.
    MOPEKS - a freeware program that generates programs that use each other to solve problems. Is this the correct route to a genuinely intelligent machine?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Solving "RangeChecks instrumentation code detected an out of range array access"

    Quote Originally Posted by wavering View Post
    Now, when it runs maybe 50 times or so it fails and I get this message:

    "Unhandled exception at 0x77B76767 (SafariPark.dll) in MOPEKS.exe: RangeChecks instrumentation code detected an out of range array access"

    So, How do I find out which of my literally hundreds of array refences is causing this problem?
    Did you debug your code?
    What does the call stack show you when this "Unhandled exception ..." happens?
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Solving "RangeChecks instrumentation code detected an out of range array access"

    Whose message is that?
    Google knows nothing about "RangeChecks instrumentation code detected an out of range array access"...
    Is it produced by one of your AI modules?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  4. #4
    Join Date
    Aug 2010
    Posts
    47

    Re: Solving "RangeChecks instrumentation code detected an out of range array access"

    Quote Originally Posted by VladimirF View Post
    Whose message is that?
    Google knows nothing about "RangeChecks instrumentation code detected an out of range array access"...
    Is it produced by one of your AI modules?
    Well, there was one reference (in a foreign language) - now there are two! It is a standard Microsoft message - see screen shot below

    Quote Originally Posted by VictorN View Post
    What does the call stack show you when this "Unhandled exception ..." happens?
    Jackpot! Thank you so much - this has totally solved the problem (which is in screenshot below but boiled down to this (which did NOT produce a warning error in VC++ 6.0 but should have)::

    Code:
      char chrArray[40];  
      chrArray[40]='\0';   // Terminate the array (should be chrArray[39]='\0')
    Yes, a silly error caused by confusing VB6 with VC++

    So, how do you do that? Well, proceed as follows:

    1. Turn on line numbers by

    Tools --> Options --> Text Editor --> C/C++ --> General --> Line Numbers

    2. Start debugging with F5 and stop on a breakpoint (important)

    Debug --> Windows --> Call Stack

    3. Click on error messsages (see screenshot below)

    Now works OK ... thanks once again
    Attached Images Attached Images   
    Last edited by wavering; November 12th, 2014 at 05:16 AM.
    MOPEKS - a freeware program that generates programs that use each other to solve problems. Is this the correct route to a genuinely intelligent machine?

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,398

    Re: Solving "RangeChecks instrumentation code detected an out of range array access"

    Quote Originally Posted by wavering View Post
    Code:
      char chrArray[40];  
      chrArray[40]='\0';   // Terminate the array (should be chrArray[39]='\0')
    You could rewrite it in more simple manner as
    Code:
      char chrArray[40] = {0};
    Victor Nijegorodov

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: Solving "RangeChecks instrumentation code detected an out of range array access"

    Another method of initializing an array to all 0 is
    Code:
    char chrArray[40] = {0};
    Your code just sets the last element to 0 but IMO setting all elements like this is easier and safer!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured