Skip to content

Commit

Permalink
Reset Buddy_objnum when buddy is deleted
Browse files Browse the repository at this point in the history
Various code assumes that Buddy_objnum maintains the invariants:
- If the guidebot exists, Buddy_objnum must refer to it.
- If no guidebot exists, Buddy_objnum must be object_none.

This was not enforced, so if the guidebot is killed, Buddy_objnum can
continue to refer to its last index.  That can cause spurious errors
later.  For example, when the player enters an energy center, if the
guidebot is dead and the guidebot's last goal was "Find energy center",
then the console reports:

```
BUG: buddy is object 28, but that object is type 255.
```

Fix that by clearing the guidebot index when the guidebot is killed.
  • Loading branch information
vLKp committed May 14, 2023
1 parent 397d582 commit c21c317
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions similar/main/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,8 @@ void obj_delete(d_level_unique_object_state &LevelUniqueObjectState, segment_arr
}
}
}
else if (LevelUniqueObjectState.BuddyState.Buddy_objnum == obj)
LevelUniqueObjectState.BuddyState.Buddy_objnum = object_none;
#endif

if (obj == Viewer) //deleting the viewer?
Expand Down

0 comments on commit c21c317

Please sign in to comment.