none
C++ Access Violation reading location 0x00421000 (Visual Studio 2010 in Windows 7)

    Question

  • I am working with OpenSceneGraph library , and I keep running into this violation issue that I would appreciate some help with. The problem is with the particular line below which happens to be the first in my main function.

     osg::ref_ptr<osg::Node> bench = osgDB::readNodeFile("Models/test.IVE");

    I have my models folder right in my directory. The error is as below.

    Unhandled exception at 0x68630A6C (msvcr100.dll) in OSG3D.exe: 0xC0000005: Access violation reading location 0x00421000.

    And this is where the problem seems to be coming up.

    /** Read an osg::Node from file. 
      * Return valid osg::Node on success,
      * return NULL on failure.
      * The osgDB::Registry is used to load the appropriate ReaderWriter plugin
      * for the filename extension, and this plugin then handles the request
      * to read the specified file.*/
    inline osg::Node*  readNodeFile(const std::string& filename)
    {
        return readNodeFile(filename,Registry::instance()->getOptions());
    }

    For one I would appreciate details on how best to tackle this kind of exception

    message in the future. Are there tools that make this easy to debug or are there

    ways to capture the exact issues and fix them? I would appreciate any help with this.


    tokorie@gmail.com


    • Edited by DataByter Friday, November 9, 2012 6:35 AM
    Thursday, November 8, 2012 3:57 PM

Answers

  • This problem seems to happen with every attempt to read a file or access lists, and occurs in every one of my example programs(project files) where I have a read file statement, even when their is no call to Reginstance object. 

    I am basically unable to get any of my programs running on my current machine, but I notice that when I move the same code to a different machine, it runs with no problem. I am wondering if it has to do with any other program I have running on my machine, including Avast.


    tokorie@gmail.com

    Tuesday, November 13, 2012 3:12 AM

All replies

  • You can get an access violation for many reasons including bugs in that library but one thing you should check are the compilation options. Because the library uses std C++ objects the library and your program must be compiled with the same compiler version and use the same compilation options.

    Thursday, November 8, 2012 5:08 PM
    Moderator
  • When you say compiled with the same compiler version, and uses the same compilation options, how do I find this information out please?

    For instance, say the lib I am using was build using visual studio 2010 for instance, is it possible for me to go one working in visual studio 2012 and expecting the compiler to be the same and the compilation options to be pretty much the same? 


    tokorie@gmail.com

    Thursday, November 8, 2012 6:52 PM
  • You must look to the library documentation. Or if the library is available in source form compile it yourself.

    In general you cannot mix a library compiled with VS2010 into a VS2012 project. They both need the exact same compiler, and exact same CRT settings, and exact same setting of debug/release.

     

    Thursday, November 8, 2012 7:30 PM
  • "say the lib I am using was build using visual studio 2010 for instance, is it possible for me to go one working in visual studio 2012"

    Hmm, in general no, VS 2012 and 2010 have different compiler and library versions. If you also have VS 2010 installed then you can change the VC toolset used by VS 2012 to the one used by VS 2010. Go to project properties and change the Platform Toolset property to v100.

    You also need to build/run the Debug or Release version depending if that library uses Debug/Release. From the error message I suspect it uses Release.

    Thursday, November 8, 2012 8:09 PM
    Moderator
  • I downloaded the VS 2010 release of OpenSceneGraph and rebuilt my application in 2010 with that but the Access Violation was not resolved even after that. Any ideas what I could do to resolve this issue please. I am working on a Windows 7 64-bit machine, if that information will help some.

    tokorie@gmail.com

    Friday, November 9, 2012 2:00 AM
  • You need to divide and conquer to isolate which piece is invalid. There are three things you can do to try and track this down.

    - You can single step into the code, checking every parameter at every step, looking for bad data or the offending address (like 0x00421000).

    - You can break up the compond statement Registry::instance()->getOptions() into separate lines so you can examine the results of each call.

    - You can examine the debugger stack window when the access violation occurs. It should show you exactly what step, with what parameters, led to the error.

    Friday, November 9, 2012 3:19 AM
  • The problem I am having with breaking up the statement  Registry::instance()->getOptions() is that I am still unable to get the downloaded source for OpenSceneGraph to compile on my machine so I can step through it. First it takes at least an hour to build that thing and then I am still working on sorting through the linker errors I get with that even as I am trying to get my own code to work. So I am left with putting try catch statements and digging as much as I can down into that to figure this out but still no luck. 

    As for the call stack, not sure how to make sense of what I have been able to observe still 

    ntdll.dll!76f215de() Unknown  [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]   ntdll.dll!76f215de() Unknown 

    ntdll.dll!76f1014e() Unknown 

    msvcr100.dll!6f650269() Unknown 

    msvcr100.dll!6f65233b() Unknown 

    osg80-osgDB.dll!0f2d5b4f() Unknown>

    OSG3DWalkingCamera.exe!osgDB::readNodeFile(const std::basic_string<char,std::char_traits<char>,std::allocator<char> > & filename={...}) Line 106 C++ 

    OSG3DWalkingCamera.exe!main(int argc=1, char * * argv=0x002d3bd0) Line 162 C++ 

    OSG3DWalkingCamera.exe!__tmainCRTStartup() Line 536 C 

    OSG3DWalkingCamera.exe!mainCRTStartup() Line 377 C 

    kernel32.dll!75d733aa() Unknown

    ntdll.dll!76f39ef2() Unknown

    ntdll.dll!76f39ec5() Unknown

    I am sort of still working on building the OpenSceneGraph Library on my machine but I have also tried running other example projects built with this library and it seems the access violation problem is not only linked to code but has something to do with settings on my machine as I am unable to run even the simplest of examples that needs to access a model, or any other file type, without encountering this problem. Is it possible that this has to do with one of the settings in Visual Studio. Any ideas what I may have configured wrong, if so?  


    tokorie@gmail.com



    • Edited by DataByter Friday, November 9, 2012 6:54 AM
    Friday, November 9, 2012 6:26 AM
  • You should check the instance returned is valid. For this you can assign returned instance to a variable and debug.

    <Returned instance type>  RegInstance = Registry::instance();
    //Then check the value of RegInstance


    Thanks, Renjith V R

    Friday, November 9, 2012 10:31 AM
  • This problem seems to happen with every attempt to read a file or access lists, and occurs in every one of my example programs(project files) where I have a read file statement, even when their is no call to Reginstance object. 

    I am basically unable to get any of my programs running on my current machine, but I notice that when I move the same code to a different machine, it runs with no problem. I am wondering if it has to do with any other program I have running on my machine, including Avast.


    tokorie@gmail.com

    Tuesday, November 13, 2012 3:12 AM