Skip to content

Commit 0b7989b

Browse files
committed
d3: fix game crash in Retribution level 12's big matcen room
When activating switches in the room with 6 matcens, this happens after a short while: ``` Assertion failure at TERRAIN_REGION (Descent3/terrain.h:218), triggered 1 time: 'x != -1 && "invalid/unset room number (-1)!"' f0 TERRAIN_REGION (x=-1) at Descent3/terrain.h:222 f1 AIPathAllocPath (obj=0x3d304b0 <Objects+150000>, ai_info=0x520000444080, goal_ptr=0x520000444250, start_room=0x3d304cc <Objects+150028>, start_pos=0x3d304d0 <Objects+150032>, end_room=0x7fb115dbe830, end_pos=0x52000044427c, rad=0, flags=0, handle=28822, ignore_obj=-1) at Descent3/aipath.cpp:1066 f2 GoalDoFrame (obj=0x3d304b0 <Objects+150000>) at Descent3/AIGoal.cpp:823 f3 AIDoFrame (obj=0x3d304b0 <Objects+150000>) at Descent3/AImain.cpp:6214 f4 ObjDoFrame (obj=0x3d304b0 <Objects+150000>) at Descent3/object.cpp:2674 f5 ObjDoFrameAll () at Descent3/object.cpp:2988 f6 GameFrame () at Descent3/GameLoop.cpp:2981 f7 GameSequencer () at Descent3/gamesequence.cpp:1221 f8 PlayGame () at Descent3/game.cpp:834 f9 MainLoop () at Descent3/descent.cpp:550 f10 Descent3 () at Descent3/descent.cpp:508 f11 oeD3LnxApp::run (this=0x7fb115a0db50) at Descent3/sdlmain.cpp:151 (gdb) up start_room=0x3d304cc <Objects+150028>, start_pos=0x3d304d0 <Objects+150032>, end_room=0x7fb115dbe830, end_pos=0x52000044427c, rad=0, flags=0, handle=28822, ignore_obj=-1) at Descent3/aipath.cpp:1066 1066 } else if (BOA_Array[BOA_INDEX(*start_room)][BOA_INDEX(*end_room)] & BOAF_TOO_SMALL_FOR_ROBOT) { (gdb) p *start_room $2 = 171 (gdb) p *end_room $3 = -1 ``` The return type of ``BOA_GetNextPath`` is int; but inside the function, ``false`` is returned, which does not fit the scheme. Judging from callsites, ``BOA_NO_PATH`` is expected instead. In some functions related to AI pathfinding, add handling or assertions for invalid room numbers.
1 parent d51ce96 commit 0b7989b

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Descent3/BOA.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ int BOA_DetermineStartRoomPortal(int start_room, vector *start_pos, int end_room
329329
bool f_making_robot_path_invalid_list, int *blocked_portal) {
330330
int i;
331331

332+
if (start_room == -1 || end_room == -1)
333+
return -1;
332334
if (start_room > Highest_room_index && end_room > Highest_room_index)
333335
return -1;
334336

@@ -566,12 +568,12 @@ int BOA_GetNextRoom(int start_room, int end_room) {
566568
int e_index = end_room;
567569

568570
if (start_room == -1 || end_room == -1) {
569-
return false;
571+
return BOA_NO_PATH;
570572
}
571573

572574
if ((!ROOMNUM_OUTSIDE(s_index)) && s_index <= Highest_room_index) {
573575
if (!Rooms[s_index].used) {
574-
return false;
576+
return BOA_NO_PATH;
575577
}
576578
} else if (ROOMNUM_OUTSIDE(s_index)) {
577579
s_index = TERRAIN_REGION(start_room) + Highest_room_index + 1;
@@ -581,7 +583,7 @@ int BOA_GetNextRoom(int start_room, int end_room) {
581583

582584
if ((!ROOMNUM_OUTSIDE(e_index)) && e_index <= Highest_room_index) {
583585
if (!Rooms[e_index].used) {
584-
return false;
586+
return BOA_NO_PATH;
585587
}
586588
} else if (ROOMNUM_OUTSIDE(e_index)) {
587589
e_index = TERRAIN_REGION(end_room) + Highest_room_index + 1;

Descent3/aipath.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ static void AIUpdatePathInfo(q_item **node_list, int start, int end) {
6060

6161
// Ok to use Highest_room_index offset stuff
6262
bool AIFindAltPath(object *obj, int i, int j, float *dist) {
63+
if (i == -1 || j == -1)
64+
return false;
6365
i = BOA_INDEX(i);
6466
j = BOA_INDEX(j);
6567

Descent3/bnode.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ static void BNode_UpdatePathInfo(pq_item **node_list, int start, int end) {
210210

211211
// Ok to use Highest_room_index offset stuff
212212
bool BNode_FindPath(int start_room, int i, int j, float rad) {
213+
if (start_room == -1)
214+
return false;
213215
bpq PQPath;
214216
int counter;
215217
pq_item *start_node = new pq_item(i, -1, 0.0f);
@@ -311,6 +313,8 @@ int BNode_FindDirLocalVisibleBNode(int roomnum, vector *pos, vector *fvec, float
311313
}
312314

313315
bn_list *bnlist = BNode_GetBNListPtr(roomnum);
316+
if (bnlist == nullptr)
317+
return -1;
314318

315319
retry:
316320

@@ -402,6 +406,7 @@ int BNode_FindClosestLocalVisibleBNode(int roomnum, vector *pos, float rad) {
402406
}
403407

404408
bn_list *bnlist = BNode_GetBNListPtr(roomnum);
409+
ASSERT(bnlist);
405410

406411
retry:
407412

0 commit comments

Comments
 (0)