title: Sending values to C# wrapped C++ dll cause Unity crash
body: <p>I have a C++ class I want to use in Unity(C#), so  I compiled a C++ dll and create a C# wrapper dll for it. I did this using SWIG.</p>
  
  <p>When I do this:</p>
  
  <pre><code>Graph g = new Graph();
  int k = g.AddNode();
  </code></pre>
  
  <p>It's fine, and I tried Debug.Log(k) to check the returned k value and it seems working right. So I think <strong>I can call functions and get returning values</strong>.</p>
  
  <p>But when I try to do this, Unity will crash:</p>
  
  <pre><code>g.AddNode(num_of_nodes);
  </code></pre>
  
  <p>Seems <strong>it will crash whenever I try to send values</strong>. No idea why this is happening.</p>
  
  <hr>
  
  <p>The class I want to wrap is <a href="http://www.cs.ucl.ac.uk/staff/V.Kolmogorov/software.html" rel="nofollow">MaxFlow library of Yuri Boykov and Vladimir Kolmogorov</a>. Anyone have any idea about how to use this library in Unity please help.</p>
  
  <hr>
  
  <p>Original C++ add_node() function:</p>
  
  <pre><code>int Graph::add_node(int num)
  {
      //assert(num &gt; 0);
  
      if (node_last + num &gt; node_max) reallocate_nodes(num);
  
      if (num == 1)
      {
          node_last -&gt; first = NULL;
          node_last -&gt; tr_cap = 0;
          node_last -&gt; is_marked = 0;
          node_last -&gt; is_in_changed_list = 0;
  
          node_last ++;
          return node_num ++;
      }
      else
      {
          memset(node_last, 0, num*sizeof(node));
  
          int i = node_num;
          node_num += num;
          node_last += num;
          return i;
      }
  }
  </code></pre>
  
  <p>SWIG generated *_wrap.cxx, functions of AddNode:</p>
  
  <pre><code>//with send param (g.AddNode(num_of_nodes)), this one will crash
  SWIGEXPORT int SWIGSTDCALL CSharp_Graph_add_node__SWIG_0(void * jarg1, int jarg2) {
    int jresult ;
    MaxFlowGraph::Graph *arg1 = (MaxFlowGraph::Graph *) 0 ;
    int arg2 ;
    MaxFlowGraph::Graph::int result;
  
    arg1 = (MaxFlowGraph::Graph *)jarg1; 
    arg2 = (int)jarg2; 
    result = (arg1)-&gt;add_node(arg2);
    jresult = result; 
    return jresult;
  }
  
  //without send param (g.AddNode()), this one works
  SWIGEXPORT int SWIGSTDCALL CSharp_Graph_add_node__SWIG_1(void * jarg1) {
    int jresult ;
    MaxFlowGraph::Graph *arg1 = (MaxFlowGraph::Graph *) 0 ;
    MaxFlowGraph::Graph::int result;
  
    arg1 = (MaxFlowGraph::Graph *)jarg1; 
    result = (arg1)-&gt;add_node();
    jresult = result; 
    return jresult;
  }
  </code></pre>
  
  <p>SWIG grnerated cs file, function of AddNode:</p>
  
  <pre><code>public int AddNode(int num)
  {
      int ret = MaxFlowGraphPINVOKE.Graph_add_node__SWIG_0(swigCPtr, num);
      return ret;
  }
  
  public int AddNode()
  {
      int ret = MaxFlowGraphPINVOKE.Graph_add_node__SWIG_1(swigCPtr);
      return ret;
  }
  </code></pre>