Finally, I have found out what was happening.
I was calling several times to GeekFunction with the same handle:
if (GeekFunction(
GCHandle.ToIntPtr(handleIndexdata),
GCHandle.ToIntPtr(handleVertexRemap),
Convert.ToUInt32(indexdata.Length),
Convert.ToUInt32(locs.data.Length), 1, null) != 0)
StatusOutput.FatalError("Geekfunction Failed");
...
if (GeekFunction(
GCHandle.ToIntPtr(handleIndexdata),
GCHandle.ToIntPtr(handleVertexRemap),
Convert.ToUInt32(indexdata.Length),
Convert.ToUInt32(locs.data.Length), 1, null) != 0)
StatusOutput.FatalError("Geekfunction Failed");
If I rebuild the handle between the calls I don't get the AccessViolationException:
try
{
if (GeekFunction(
handleBoneIndices.AddrOfPinnedObject(),
handleVertexRemap.AddrOfPinnedObject(),
Convert.ToUInt32(boneindices.data.Length),
Convert.ToUInt32(sizeof(VertexData.Index4)), null) != 0)
StatusOutput.FatalError("GeekFunctionFailed: boneIndices");
}
finally
{
handleBoneIndices.Free();
handleVertexRemap.Free();
}
**handleVertexRemap = GCHandle.Alloc(vertexRemap, GCHandleType.Pinned);**
try
{
if (scePsp2VertexCacheApplyVertexRemapping(
handleBoneIndices.AddrOfPinnedObject(),
handleVertexRemap.AddrOfPinnedObject(),
Convert.ToUInt32(boneindices.data.Length),
Convert.ToUInt32(sizeof(VertexData.Index4)), null) != 0)
StatusOutput.FatalError("scePsp2VertexCacheApplyVertexRemapping Failed: boneIndices");
}
finally
{
handleBoneIndices.Free();
handleVertexRemap.Free();
}
thank you for your help. The tests with the simpler function helped a lot.