views:

66

answers:

1

Hi,

something strange is happening to my code. I am using a library which is supposed to work perfectly (nglib from the open-source Netgen mesher). I can link and include everything, but I cannot use this library :

The object I want to use is Ng_Mesh* mesh = Ng_NewMesh ();

The Ng_NewMesh() method is :

   DLL_HEADER Ng_Mesh * Ng_NewMesh ()
   {
      Mesh * mesh = new Mesh;  
      mesh->AddFaceDescriptor (FaceDescriptor (1, 1, 0, 1));
      return (Ng_Mesh*) (void*) mesh;
   }

When I go to locals, it is seen as a void** referring to *mesh which is a void*. It is not NULL because I can add points and other stuff to this object, but with some functions, I get an exception :

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

at nglib.Ng_GetPoint(Void** , Int32 , Double* )
at ForwardModelingPlugin.CustomMeshVol3D.tesselate(CustomMeshVol3D* )

nglib.Ng_GetPoint is supposed to have as arguments (Ng_Mesh*, Int32, Double*) which explains this exception.

I don't know why this casting is happening.

+5  A: 

Here it says:

/// Data type for NETGEN mesh
typedef void * Ng_Mesh;

therefore Ng_Mesh* mesh; is the same as void** mesh;

Eugen Constantin Dinca
Righto, which means the OP is casting a `void*` to a `void**`. Hmmm...
Justin Ardini
@Eugen Thanks, that's seems to be logical@ Justin : Isn't that a/the problem?
ChRtS
@ChRtS: Yes, that would cause your memory corruption issue.
Justin Ardini
I highly doubt that the 'exotic' way of going from Mesh* to Ng_Mesh* is the cause of the memory corruption.You should look for the usual suspects: using unallocated/deleted objects, writing out of objects bounds, not using/misusing your API way to create/destroy objects etc.
Eugen Constantin Dinca
I effectively miused the API, thanks!
ChRtS