fabmax / physx-jni

Java JNI bindings for Nvidia PhysX
MIT License
88 stars 9 forks source link

Crash without log #18

Closed haubna closed 3 years ago

haubna commented 3 years ago

I am not sure why but this code (extended sample code) crashes when using the convex shapes. Creating no log whatsoever and it doesn't even crash all the time. I might be using the API wrong though.

https://pastebin.com/21gDbdpE

fabmax commented 3 years ago

You are releasing your convexMesh and material to early (in lines 149 and 150, convexMesh is even released a second time in line 152). These objects are used by PxConvexMeshGeometry during simulation afterwards and if they are already released this results in undefined behavior and/or a crash. Since this happens in native code outside the JVM there is also no stack trace or other kind of error message (that's the 'beauty' of native code development...).

Fix is easy: Keep the references to convexMesh and material and release them in the end (when scene and the other stuff is released). For the material you can also re-use the material created in the main method before, instead of creating a new one for the convex mesh.

haubna commented 3 years ago

Still crashing unfortunately. Code that causes the crash: https://pastebin.com/xcaLuuPD

I have also tried to keep everything in memory from the Convex Actor (and not calling there destroy() functions) and it still crashed.

fabmax commented 3 years ago

Ah this is a weird bug I experienced myself a while ago: For some reason it is required to clear the eENABLE_PCM flag on scene creation. I have no idea what's the reason for that, but it seems to be a PhysX problem (maybe related to my build setup, compiler / optimization settings, I don't know...)

The workaround is to not use PCM (uncomment line 26) then it should work fine.

haubna commented 3 years ago

Ok thanks! :)

haubna commented 3 years ago

I've rebuilt the PhysX libs and it works now (as suggested in your how to build it by yourself)! Link to the builds (only windows builds): https://drive.google.com/file/d/1kCBU_WKI5g0pnJ_EwDe7vp2si4dBWjDe/view?usp=sharing https://drive.google.com/file/d/1AmLDzl9W2ukVgU-ez_RcCAT7zhj_mbB6/view?usp=sharing

fabmax commented 3 years ago

Thanks for the info! I reinstalled my Visual Studio and now my build seems to work as well. Update should be up soon...