Skip to content

Commit 37a98b8

Browse files
committed
Check B->parent_sig before checking B->parent in objcollide.cpp.
Could cause problems with recycled objects (specifically, I had a crash once because "Objects[B->parent].instance" was well over MAX_SHIPS due to being a weapon instead of a ship, causing the "Ships[Objects[B->parent].instance].team" reference to fail hard).
1 parent a5b705b commit 37a98b8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

code/object/objcollide.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ void obj_add_pair( object *A, object *B, int check_time, int add_to_end )
389389
}
390390

391391
// for nonplayer ships, only create collision pair if close enough
392-
if ( (B->parent >= 0) && !(Objects[B->parent].flags & OF_PLAYER_SHIP) && (vm_vec_dist(&B->pos, &A->pos) < (4.0f*A->radius + 200.0f)) )
392+
if ( (B->parent >= 0) && !((Objects[B->parent].signature == B->parent_sig) && (Objects[B->parent].flags & OF_PLAYER_SHIP)) && (vm_vec_dist(&B->pos, &A->pos) < (4.0f*A->radius + 200.0f)) )
393393
return;
394394
}
395395
}
@@ -398,6 +398,7 @@ void obj_add_pair( object *A, object *B, int check_time, int add_to_end )
398398
if (check_collision == collide_ship_weapon) {
399399
// weapon is B
400400
if ( (B->parent >= 0)
401+
&& (Objects[B->parent].signature == B->parent_sig)
401402
&& !(Objects[B->parent].flags & OF_PLAYER_SHIP)
402403
&& (Ships[Objects[B->parent].instance].team == Ships[A->instance].team)
403404
&& (Ship_info[Ships[A->instance].ship_info_index].flags & SIF_SMALL_SHIP)
@@ -1620,7 +1621,7 @@ void obj_collide_pair(object *A, object *B)
16201621
}
16211622

16221623
// for nonplayer ships, only create collision pair if close enough
1623-
if ( (B->parent >= 0) && !(Objects[B->parent].flags & OF_PLAYER_SHIP) && (vm_vec_dist(&B->pos, &A->pos) < (4.0f*A->radius + 200.0f)) ) {
1624+
if ( (B->parent >= 0) && !((Objects[B->parent].signature == B->parent_sig) && (Objects[B->parent].flags & OF_PLAYER_SHIP)) && (vm_vec_dist(&B->pos, &A->pos) < (4.0f*A->radius + 200.0f)) ) {
16241625
collision_info->next_check_time = -1;
16251626
return;
16261627
}
@@ -1631,6 +1632,7 @@ void obj_collide_pair(object *A, object *B)
16311632
if (check_collision == collide_ship_weapon) {
16321633
// weapon is B
16331634
if ( (B->parent >= 0)
1635+
&& (Objects[B->parent].signature == B->parent_sig)
16341636
&& !(Objects[B->parent].flags & OF_PLAYER_SHIP)
16351637
&& (Ships[Objects[B->parent].instance].team == Ships[A->instance].team)
16361638
&& (Ship_info[Ships[A->instance].ship_info_index].flags & SIF_SMALL_SHIP)

0 commit comments

Comments
 (0)