Fix wrong variable in physics collision loop#1689
Fix wrong variable in physics collision loop#1689Azaezel merged 1 commit intoTorqueGameEngines:developmentfrom
Conversation
In Player::updatePos(), when processing physics collision results, the code was incorrectly using col.object instead of colCheck.object when checking if the collision object is a player. This caused: - First iteration: col.object is uninitialized (zeroed), leading to null pointer access - Subsequent iterations: col.object contains the previous iteration's value, causing incorrect type checks The fix changes col.object to colCheck.object to properly check the current collision object.
|
While this may appear to be incorrect at first in context it is checking col.object for whether or not it is a playerobject type. This value is checked to see if a current collision in the queue can be overwritten. What this change does is if it finds a playerObject in the loop it handles that curCheck object immediately but the next object if it is not a playerObject type it will be overwritten and therefore the playerobject is no longer the last collision in the list. Increasing the risk of a playerObject collision being overwritten in the collision queue before it has had a chance to be resolved. for example if the collision list comes in like this: the last object to be queued would be the waterobject and the first object would be the playerobject. what the code was originally doing was playerobject would always be added last so there is less chance of it reaching timeout and being overwritten. |
|
That makes sense, I went over the logic many times before making the PR. While it did resolve issues in my project but I now see I may have to go a different route to make sure the player collision doesn't get lost in the exact case you explained. |
Summary
Fixes a bug in
Player::updatePos()where the wrong variable was used when iterating through physics collision results.The Bug
In the physics-enabled collision handling loop at line 5172: