Stop leaving stale bodies on a trigger's list


A trigger keeps a list of what is inside it, which is what
collisionCount counts and what bodyExited is emitted from. A body is
taken off that list when PhysX reports its touch as lost, which is the
ordinary way out and works. Two things never got that far and left a
body on the list for as long as the trigger lived, both of them counting
a body that is not inside it any more, and one of them keeping a pointer
to a body that no longer exists at all.

A body deleted while still inside is the one that leaves the pointer.
PhysX does report the pair as lost when the actor is released, but the
report points at a shape that has already been taken away and is
skipped. So follow the body's own destroyed() signal, which runs from
~QObject: the list is searched by comparing pointers rather than by
casting one back to what it can no longer be.

Nothing is reported for such a body, in either direction, since
bodyExited would pass a half destroyed body to a handler and there is no
body left to tell. collisionCount does count it out, so say in the
documentation that a list kept by hand from these signals has to be
cleared of deleted bodies another way. Which a handler can now do from
bodyEntered, for the body it is passed, and the count is reported once
rather than twice.

A body that turns sendTriggerReports off while inside is the other one:
the flag was read again as it left, so a body that no longer asked to be
reported was never taken off the list it was put on when it did. Ask the
trigger to take it off whatever the body says now; taking off one that
was never on it does nothing.

A body whose collision shapes are taken away while inside is a third way
onto that list, and is not closed here: the report that would say so
points at a shape that is already gone, so it cannot be attributed to a
body from the callback at all. Closing it takes the frame saying which
node had its shapes replaced, which the patch above does.

Add tests/auto/trigger_stale_bodies for both of them: a body deleted
while inside, which has to stop counting without being reported as
having left, and a body that turns sendTriggerReports off while inside,
which still has to come off the list when it leaves.

Pick-to: 6.12 6.11
Change-Id: I14cfdabcd35e37604bb179a8f2f5ac114e4ec9b6
Reviewed-by: Kristoffer Skau <kristoffer.skau@qt.io>
commit6115408c75a3dd93d1c13bd9db5fc23d7b93f5f6
parent84718798c38802acfd8bc214d2fe7b92cc5d7863
authorJonas Karlsson <jonas.karlsson@qt.io>
committerJonas Karlsson <jonas.karlsson@qt.io>
commit timeWed, 16 Sep 2026 13:16:01 +0000