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

Freeze by endless loops in Physics #84

Open
meekee7 opened this issue Apr 25, 2020 · 0 comments
Open

Freeze by endless loops in Physics #84

meekee7 opened this issue Apr 25, 2020 · 0 comments
Labels

Comments

@meekee7
Copy link
Contributor

meekee7 commented Apr 25, 2020

Sometimes the game freezes because it is stuck in an endless loop in physics code.

Steps to reproduce

  1. Pick up a "storable" object like a pistol or keycard.
  2. Store the object in your inventory.
  3. Move so that you stand directly in front of a wall (doors work too)
  4. Keep storing and retrieving the object in such a way that the hand or the object touch the wall.

Personally I use the pistols in the security entrance at the beginning of the Industrial Town level for testing this.

The bug only rarely occurs in Debug builds, but is easy to reproduce in Release builds.

The cause

The problem is caused by two loops in physics code that are supposed to normalize vectors. The code is almost the same for both. Those loops are Pelvis.cpp lines 1162 to 1187 and Xob_bc.cpp lines 3738 to 3763.

The loop is supposed to end when a float variable L becomes smaller than a certain threshold. However, the comparison does not work anymore when L becomes NaN. This happens because it was calculated from the vector entries, which are all NaN as well. Current research has shown that they were already NaN before the loop. Why this happens needs to be investigated.

Solution approaches

Ending the loop when L becomes NaN prevents the game from freezing. But the vector is still full of NaNs and new problems occur immediately:

  • The player cannot jump anymore
  • When moving, there are very frequent little jumps. Sometimes the player can barely move at all
  • The arm cannot be used anymore
  • In summary, the game is left in an unplayable state.

An alternative approach is to do the bailout described above, but also set the vector that was supposed to be normalized to a valid default value. That default value needs yet to be determined. After a first test with a quad-0.25 vector, various physics glitches with held items occur, but the game remains playable.

The best solution is to find out why the vector became NaN in the first place.

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

No branches or pull requests

2 participants