Clean invalid robot joint data on load

Some levels have robots with n_joints=0 and an invalid offset.  If the
number of joints is zero, the offset is irrelevant.  Reset it to 0, so
that a later call to partial_range will not trap.

Reported-by: kakhome1 <https://github.com/dxx-rebirth/dxx-rebirth/issues/485>
This commit is contained in:
Kp 2020-01-08 04:32:39 +00:00
parent b0185e44ad
commit 47a3df9fab

View file

@ -183,6 +183,16 @@ static void jointlist_read(PHYSFS_File *fp, array<jointlist, N_ANIM_STATES> &jl)
{
i.n_joints = PHYSFSX_readShort(fp);
i.offset = PHYSFSX_readShort(fp);
if (!i.n_joints)
/* The custom campaign `Descent 2: Enemy Vignettes` has
* custom robots with invalid joints. These joints have
* invalid offsets, but `n_joints` of 0. This makes the
* invalid data easy to detect and clean.
*
* When the number of joints is zero, discard the loaded
* offset and set it to 0, which will always be in range.
*/
i.offset = 0;
}
}