macite/swingame

VectorNormal (Pascal) crashes when passed a zero vector

Closed this issue · 1 comments

Here, try it:

program VectorNormalCrashTest;
uses SwinGame, sgTypes;
begin
  VectorNormal(VectorTo(0, 0));
end.
EInvalidOp: Invalid floating point operation

The cause is fairly obvious: VectorNormal is dividing by the magnitude (the variable isn't helpfully named, either). This would be less of a hassle if I was calling VectorNormal directly. Unfortunately, I'm not - it's happening from CollideCircleLine, and refactoring my code to avoid that would be a lot of trouble.

You've already done the hard part of diagnosing it, you might as well submit a pull request and get credit for the fix. :)