foxygit / doom Log in
commit 4fd19a0f991e4977e4ac65f7cca3321be0da1a40
Author:     Noseey <omega_1986@hotmail.com>
AuthorDate: Tue Apr 15 16:59:12 2025 +0200
Commit:     GitHub <noreply@github.com>
CommitDate: Tue Apr 15 17:59:12 2025 +0300

    Hexen: Partial fix for Segfault in P_BounceWall (#1740)

    * Hexen: commented out solution to segfault.

    * Hexen: partial fix for unset bestslideline.

    * Hexen: Remove commented out fix.

    * Hexen: whitespace fix

    * Hexen: Add comment for bestslideline error.

    * Hexen: Whitespace fix

    * Hexen: Adding IF braces and fixing whitespaces.
---
 src/hexen/p_local.h |  1 +
 src/hexen/p_map.c   | 29 +++++++++++++++++++++++++++++
 src/hexen/sv_save.c |  3 +++
 3 files changed, 33 insertions(+)

diff --git a/src/hexen/p_local.h b/src/hexen/p_local.h
index 3c0c09cf..29ca0402 100644
--- a/src/hexen/p_local.h
+++ b/src/hexen/p_local.h
@@ -292,6 +292,7 @@ boolean P_CheckSight(mobj_t * t1, mobj_t * t2);
 void P_UseLines(player_t * player);
 boolean P_UsePuzzleItem(player_t * player, int itemType);
 void PIT_ThrustSpike(mobj_t * actor);
+void P_InitSlideLine(void);

 boolean P_ChangeSector(sector_t * sector, int crunch);

diff --git a/src/hexen/p_map.c b/src/hexen/p_map.c
index be6a2928..6a388601 100644
--- a/src/hexen/p_map.c
+++ b/src/hexen/p_map.c
@@ -1450,6 +1450,25 @@ void P_SlideMove(mobj_t * mo)
     }
 }

+//============================================================================
+//
+// P_InitSlideLine
+//
+//============================================================================
+
+void P_InitSlideLine(void)
+{
+    // use relevant parts from first bestslideline in demo1 (hexen.wad)
+    static vertex_t initvertex1 = {-77594624, 37748736};
+    static line_t initslideline = {&initvertex1, NULL, 0, 6291456, 0, 0, 0, 0,
+                    0, 0, 0, { 0, 0 }, { 0, 0, 0, 0 }, 0, NULL, NULL, 0, NULL};
+
+    if (bestslideline == NULL)
+    {
+        bestslideline = &initslideline;
+    }
+}
+
 //============================================================================
 //
 // PTR_BounceTraverse
@@ -1529,6 +1548,16 @@ void P_BounceWall(mobj_t * mo)
     P_PathTraverse(leadx, leady, leadx + mo->momx, leady + mo->momy,
                    PT_ADDLINES, PTR_BounceTraverse);

+    // P_BounceWall call on a tall sector after fresh game start
+    // without the player sliding along any walls before.
+    // For more details check:
+    // https://github.com/chocolate-doom/chocolate-doom/issues/1732
+    // https://github.com/chocolate-doom/chocolate-doom/issues/1160
+    if (bestslideline == NULL)
+    {
+        I_Error("P_BounceWall: No bestslideline was set. Try bumping walls.");
+    }
+
     side = P_PointOnLineSide(mo->x, mo->y, bestslideline);
     lineangle = R_PointToAngle2(0, 0, bestslideline->dx, bestslideline->dy);
     if (side == 1)
diff --git a/src/hexen/sv_save.c b/src/hexen/sv_save.c
index 48d81aeb..007e6334 100644
--- a/src/hexen/sv_save.c
+++ b/src/hexen/sv_save.c
@@ -2151,6 +2151,9 @@ void SV_LoadGame(int slot)
             players[i].readyArtifact = players[i].inventory[inv_ptr].type;
         }
     }
+
+    // Set Bestslideline after loading
+    P_InitSlideLine();
 }

 //==========================================================================