Access violation writing location 0x0000000C error while calling c++ dll from c#

0

What I do:

  1. I called a C++ dll from C#. It works fine but when I exit the process, it shows the following error

    exe stoped working

  2. When I debug the code in Visual Studio it shows

    Unhandled exception at 0x773C77A2 (ntdll.dll) in Test.exe: 0xC0000005: Access violation writing location 0x0000000C.

The code I have used in C#:

using System;
namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Utility test1 = new Utility();
            algobucket test2 = new algobucket();

            Console.WriteLine("Algobucket Algorithm\n ");
            int k = 1;
            byte[] imageData1 = new byte[5000000];
            byte[] imageData2 = new byte[5000000];
            int[] target1 = new int[1000];

            while (k == 1)
            {
                int m;
               
                test1.CameraRead(imageData1);
                int a = test2.iristracker(imageData1, 640, 480, imageData2, target1, 1000);
                m = test1.ImageShow(imageData2);

                if (m == 1)
                {
                    Console.WriteLine("Stopped");
                    break;                    
                }
            }

            Console.WriteLine("Exited");
        }
    }
}

In the above code the dll is called in the lines

                test1.CameraRead(imageData1);
                int a = test2.iristracker(imageData1, 640, 480, imageData2, target1, 1000);
                m = test1.ImageShow(imageData2);

The CameraRead() and ImageShow() are called from a dll and the iristracker() is called from another dll.

Utility.h

#ifndef UTILITY_H
#define UTILITY_H

class Utility
{

public:
 int CameraRead(unsigned char* Output);
 int ImageShow(unsigned char* Input);
int DrawRectOnImage(unsigned char* image,int* rect,int n);
int DrawPointOnImage(unsigned char* image,int* rect,int n);
};

#endif  /* UTILITY_H */

Iristracker.hpp

#ifndef IRISTRACKER_HPP
#define IRISTRACKER_HPP
#include <iostream>
class algobucket 
{

public:


 int iristracker(unsigned char* input,int width,int height,unsigned char* Output,int* output,int n,std::string xml_path="");  

};

#endif  /* IRISTRACKER_HPP */

Swig Interface Utility.i

%module testing

%{
#include "Utility.h"
%}
%include "arrays_csharp.i"

  %apply unsigned char OUTPUT[] { unsigned char* Output}
   %apply unsigned char INPUT[] { unsigned char* Input}
   %apply unsigned char INPUT[] { unsigned char* image}
  %apply int INPUT[] { int* rect}
 %include "Utility.h"

Swig Interface Iris.i

%module algo

%{
#include "IrisTracker.hpp"
%}
%include "arrays_csharp.i"
%include "std_string.i"
  %apply unsigned char INPUT[] { unsigned char* input}
  %apply unsigned char OUTPUT[] { unsigned char* Output}
  %apply int OUTPUT[] { int* output}
 %include "IrisTracker.hpp"

Here missed any typemap for Memory handling for above swig interface file

What do I have to do to solve this issue?

c#
c++
swig
asked on Stack Overflow Apr 13, 2016 by Cibin William • edited Apr 13, 2016 by Cibin William

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0