Skip to content

Commit

Permalink
tr1/camera: fix potential division by zero
Browse files Browse the repository at this point in the history
Resolves #1671.
  • Loading branch information
lahm86 committed Oct 5, 2024
1 parent d71e2dd commit a6561f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/tr1/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- fixed Lara's head not matching the braid if in use when she is killed by the T-rex (#1549)
- fixed `/endlevel` displaying a success message in the title screen
- fixed Story So Far feature looping cutscenes forever (#1551, regression from 4.4)
- fixed a rare crash related to the camera that could affect custom levels (#1671)
- improved object name matching in console commands to work like TR2X
- improved vertex movement when looking through water portals even more (#1493)
- improved console commands targeting creatures and pickups (#1667)
Expand Down
11 changes: 9 additions & 2 deletions src/tr1/game/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -782,14 +782,21 @@ static void M_Clip(
const int32_t target_y, const int32_t left, const int32_t top,
const int32_t right, const int32_t bottom)
{
const int32_t x_diff = *x - target_x;
const int32_t y_diff = *y - target_y;

if ((right > left) != (target_x < left)) {
*y = target_y + (*y - target_y) * (left - target_x) / (*x - target_x);
if (x_diff) {
*y = target_y + (left - target_x) * y_diff / x_diff;
}
*x = left;
}

if ((bottom > top && target_y > top && *y < top)
|| (bottom < top && target_y < top && (*y) > top)) {
*x = target_x + (*x - target_x) * (top - target_y) / (*y - target_y);
if (y_diff) {
*x = target_x + (top - target_y) * x_diff / y_diff;
}
*y = top;
}
}
Expand Down

0 comments on commit a6561f1

Please sign in to comment.