So i'm trying to run a c++ native function in a dll from some c# code. And it works fine, however, when i use 'out' in my function call i get a memory access violation. This is what it looks like:
C# function
[DllImport(pluginName)]
public static extern IntPtr AddTriangleFixtuers(ShapeDef shapeDef, IntPtr toBody, ref Vector2 vertices, int triangleCount, Vector3 row1, Vector3 row2, out int fixtureCount);
...
int test = 1;
B2D.AddTriangleFixtuers(def, body.body, ref shapeTriangles[0], shapeTriangles.Length/3, firstRow, secondRow, out test);
C++ function
EXTERN_DLL_EXPORT b2Fixture* __stdcall AddTriangleFixtuers(ShapeDef shapeDef, IntPtr* toBody, b2Vec2* vertices, int triangleCount, b2Vec3 row1, b2Vec3 row2, int& fixtureCount) {
fixtureCount = 0;
b2Fixture* lastFixture = NULL;
return lastFixture;
}
I've minimized the code to highlight the issue i'm running into. As soon as i try to set fixtureCount in the c++ code to anything i get the following error:
An exception of type 'System.AccessViolationException' occurred in Assembly-CSharp.DLL but was not handled in user code Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.