Memory Violation when calling DLL function from c#


I have created dll using swig from LibrDWG. When I try to call one of the functions:

var layers= LibreDWG.dwg_get_layers(dwg_Data);

I got memory violation exeption:

Exception thrown at 0x00000000622A995F (LibreDWG.dll) in LibreDWG_WPF.exe: 0xC0000005: Access violation reading location 0x0000000000000030.

The error only occur only for large files, smaller ones works fine. Code of wrapper generated by swig:

  public static SWIGTYPE_p_p__dwg_object_LAYER dwg_get_layers(Dwg_Data dwg) {
    global::System.IntPtr cPtr = LibreDWGPINVOKE.dwg_get_layers(Dwg_Data.getCPtr(dwg));
    SWIGTYPE_p_p__dwg_object_LAYER ret = (cPtr == global::System.IntPtr.Zero) ? null : new SWIGTYPE_p_p__dwg_object_LAYER(cPtr, false);
    return ret;

And the c code:

EXPORT Dwg_Object_LAYER **
dwg_get_layers (const Dwg_Data *dwg)
  unsigned int i;
  unsigned int num_layers = dwg_get_layer_count (dwg);
  Dwg_Object_LAYER **layers;

  assert (dwg);
      = (Dwg_Object_LAYER **)calloc (num_layers, sizeof (Dwg_Object_LAYER *));
  for (i = 0; i < num_layers; i++)
    layers[i] = dwg->layer_control.entries[i]->obj->tio.object->tio.LAYER;
  return layers;

Do you have any suggestions? Thanks for any help.


0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0