locked
Attempted to read or write protected memory RRS feed

  • Question

  • Hi All,

    I have used the vtk with c#."Attempted to read or write protected memory. This is often an indication that other memory is corrupt" error occured while i calling some function from vtk.

    Code snippet below

    public partial class VisualLine : vtkParametricFunction

    {

     public VisualLine() : base(IntPtr.Zero,false,false)

           {
               this.SetMinimumU(0);//error occure while executing this line.

    }

    }

    Please suggest me.what is the error and solution for the same.


    MSS

    • Moved by Kristin Xie Wednesday, July 15, 2015 8:24 AM third-party library related
    Thursday, July 2, 2015 11:33 AM

All replies

  • An AccessViolationException is usually caused by unmanaged code or some kind of a marshalling/interop/configuration mismatch.  Your code snippet is just the tiniest little glimpse of what's going on.

    If this.SetMinimumU(0) is causing an error, then it's because this is bad, or SetMinimumU has done something bad.

    Either way, the problem is not in the code you have displayed.

    I'm slightly interested in the IntPtr.Zero thing.  That tells me that you are using IntPtr and are likely interoperating with unmanaged code somewhere.  That's probably where the problem is.

    Thursday, July 2, 2015 12:26 PM
  • Thanks for reply,

    I cannot able to solve this issue still,I mentioned some hints,If  get any idea from this hints,Please suggest the solution

    1)Code snippet as expanded is below 

     public partial class VisualLine: vtkParametricFunction
        {
           public VisualLine():base(IntPtr.Zero,false,false)   
           { 

               this.SetMinimumU(0);
               this.SetMaximumU(1.0 - 1.0e-10);

               this.SetJoinU(0);
               this.SetTwistU(0);
               this.SetClockwiseOrdering(0);
               this.SetDerivativesAvailable(0);
             
           }

    2)SetMinimumU(0).Actually this function from the vtkParametricFunction class.the function declaration in vtk such as 

    public virtual void SetMinimumU(double _arg);

    3)vtkParametricFunction,this is a vtk class which has the constructor with 3 parameter like          "public vtkParametricFunction(IntPtr rawCppThis, bool callDisposalMethod, bool strong);"


    MSS

    Friday, July 3, 2015 7:17 AM
  • This exception can mean exactly two things:

    - You are using unsafe code, propably some old native C++ librariy or COM library. And naturally someone screwed up the pointer arythmethic (it's so damn easy to do, .NET was designed to not let us handle pointers needlessly).

    - You have faulty hardware in that computer. RAM or CPU most likely, but it could also be any piece connecting them.

    Does this error message happen randomly or only on one system?
    Asume hardware fault first. Make proper tests (MemTest for example).

    Does it happen on many computers? Question if the library used was written properly and if it is used properly. Also exclude you got a binary damaged copy of the library that you keep distributing.

    Friday, July 3, 2015 8:56 AM
  • 3)vtkParametricFunction,this is a vtk class which has the constructor with 3 parameter like          "public vtkParametricFunction(IntPtr rawCppThis, bool callDisposalMethod, bool strong);"

    I'm not familiar with vtk.  If you think you need vtk specific information to solve this then perhaps you should look for a vtk forum.

    The usual debugging techniques would be to figure out if the object is in a valid state.  Figure out where you've passed the VisualLine object and what you've done with it.  Check to see if the object has been disposed or something silly like that.

    Friday, July 3, 2015 11:53 AM