NVIDIAGameWorks / PhysX

NVIDIA PhysX SDK
Other
3.11k stars 793 forks source link

Strange read/write overlapping API calls errors #647

Closed SNMetamorph closed 9 months ago

SNMetamorph commented 9 months ago

I getting these errors spamming from PhysX (version 4.1.2), but I don't use any multithreading since my application is completely single-threaded. изображение

Also my code of running simulation is pretty simple and looks like this изображение What i'm doing wrong?

msauter-nvidia commented 9 months ago

Are you by any chance adding forces within contact callbacks? That could be a scenario that triggers this. Write operations are not allowed in contact callbacks.

SNMetamorph commented 9 months ago

Are you by any chance adding forces within contact callbacks? That could be a scenario that triggers this. Write operations are not allowed in contact callbacks.

@msauter-nvidia yes, exactly this happens. Interesting that I didn't found any information about write operations restrictions inside contact callbacks in documentation.

So next, I need to do actions that now runs in contact callback. How can I do these actions? Create some queue, push information in it inside contact callback, and before running simulation code use this information to do actions. Will this work?

msauter-nvidia commented 9 months ago

It is documented in PxSimulationEventCallback:

"SDK state should not be modified from within the callbacks. In particular objects should not be created or destroyed. If state modification is needed then the changes should be stored to a buffer and performed after the simulation step"

The solution is exactly what you described: you need to write the changes you want to do into some sort of buffer and apply them after fetchResults() has returned.

SNMetamorph commented 9 months ago

It is documented in PxSimulationEventCallback:

"SDK state should not be modified from within the callbacks. In particular objects should not be created or destroyed. If state modification is needed then the changes should be stored to a buffer and performed after the simulation step"

The solution is exactly what you described: you need to write the changes you want to do into some sort of buffer and apply them after fetchResults() has returned.

Thanks