Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up a triangle mesh #17

Open
jjb-pro opened this issue Mar 9, 2024 · 2 comments
Open

Setting up a triangle mesh #17

jjb-pro opened this issue Mar 9, 2024 · 2 comments

Comments

@jjb-pro
Copy link

jjb-pro commented Mar 9, 2024

Hello,
I have the following problem:
I am trying to set up a triangle mesh using the NVIDIA documentation: NVIDIA Docs. When I run the code, I get a warning that the triangles are too large. However, this is not true (max. 1.5). I also get the following error:

C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\physx-sys-0.11.1\physx/physx\source/geomutils/src/cooking\GuCookingTriangleMesh.cpp (202) : warning : TriangleMesh: triangles are too big, reduce their size to increase simulation stability!

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
   at MagicPhysX.NativeMethods.phys_PxCookTriangleMesh(MagicPhysX.PxCookingParams*, MagicPhysX.PxTriangleMeshDesc*, MagicPhysX.PxOutputStream*, MagicPhysX.PxTriangleMeshCookingResult*)
--------------------------------

And here is my code:

PxTriangleMeshDesc meshDesc = new();

meshDesc.points.count = (uint)subMesh.Vertices.Length;
meshDesc.points.stride = (uint)sizeof(PxVec3);
meshDesc.points.data = (void*)Marshal.UnsafeAddrOfPinnedArrayElement(subMesh.Vertices.ToPxVector3(), 0);

meshDesc.triangles.count = (uint)subMesh.Indices.Length / 3;
meshDesc.triangles.stride = 3 * sizeof(uint);
meshDesc.triangles.data = (void*)Marshal.UnsafeAddrOfPinnedArrayElement(subMesh.Indices, 0);

PxCookingParams cookingParams = new();

PxDefaultMemoryOutputStream writeBuffer = new();
PxTriangleMeshCookingResult result = PxTriangleMeshCookingResult.Success;
bool status = phys_PxCookTriangleMesh(&cookingParams, &meshDesc, (PxOutputStream*)(&writeBuffer), &result);
if (!status)
     return;

Another problem is in the code after that:

PxDefaultMemoryInputData readData = new(writeBuffer.GetData(), writeBuffer.GetSize());    // ???
PxPhysics_createTriangleMesh_mut(_physics, &writeBuffer);

According to the documentation, you can create PxDefaultMemoryInputData with two parameters writeBuffer.getData(), writeBuffer.getSize(), but in C# the struct only declares the field structgen_pad0.

Thank you very much for your help and work on this project!

@Dlory
Copy link

Dlory commented Jun 25, 2024

I met the same problem, did you solve it?

@jjb-pro
Copy link
Author

jjb-pro commented Jun 26, 2024

I met the same problem, did you solve it?

I switched to PhysX.NET eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants