Skip to content

Commit

Permalink
Fix crash on invalid (-1) sequence.
Browse files Browse the repository at this point in the history
  • Loading branch information
Garey Akhmetshin committed Apr 12, 2022
1 parent ee24640 commit 4f1c268
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,5 @@ dkms.conf
*.exe
*.out
*.app

CMakeSettings.json
6 changes: 2 additions & 4 deletions src/animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,10 @@ mstudioanim_t* StudioGetAnim(model_t* m_pSubModel, mstudioseqdesc_t* pseqdesc)
paSequences = (cache_user_t*)IEngineStudio.Mem_Calloc(16, sizeof(cache_user_t)); // UNDONE: leak!
m_pSubModel->submodels = (dmodel_t*)paSequences;
}
#if 0 // todo there crash in some servers
if (!IEngineStudio.Cache_Check((struct cache_user_s*)&(paSequences[pseqdesc->seqgroup])))
{
IEngineStudio.LoadCacheFile(pseqgroup->name, (struct cache_user_s*)&paSequences[pseqdesc->seqgroup]);
}
#endif
return (mstudioanim_t*)((byte*)paSequences[pseqdesc->seqgroup].data + pseqdesc->animindex);
}

Expand Down Expand Up @@ -921,7 +919,7 @@ void EXT_FUNC SV_StudioSetupBones(model_t* pModel, float frame, int sequence, co
g_pstudiohdr = (studiohdr_t*)IEngineStudio.Mod_Extradata(pModel);

// Bound sequence number
if (sequence < 0 || sequence >= g_pstudiohdr->numseq)
if (!g_pstudiohdr || sequence < 0 || sequence >= g_pstudiohdr->numseq)
sequence = 0;

pbones = (mstudiobone_t*)((byte*)g_pstudiohdr + g_pstudiohdr->boneindex);
Expand Down Expand Up @@ -1078,7 +1076,7 @@ void EXT_FUNC SV_StudioSetupBones(model_t* pModel, float frame, int sequence, co
if (
player_params[player].sequencetime &&
(player_params[player].sequencetime + 0.2 > player_params[player].m_clTime) &&
(player_params[player].prevsequence < g_pstudiohdr->numseq))
(player_params[player].prevsequence >= 0 && player_params[player].prevsequence < g_pstudiohdr->numseq))
{
// blend from last sequence
static float pos1b[MAXSTUDIOBONES][3];
Expand Down
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,9 @@ void PlayerPostThinkPost(edict_t* pEntity)
player_params[id].controller[3] = _host_client->edict->v.controller[3];
player_params[id].blending[0] = _host_client->edict->v.blending[0];
player_params[id].blending[1] = _host_client->edict->v.blending[1];
if (player_params[id].sequence < 0)
player_params[id].sequence = 0;

// sequence has changed, hold the previous sequence info
if (player_params[id].sequence != player_params[id].prevsequence)
{
Expand Down Expand Up @@ -584,6 +587,10 @@ int (AddToFullPackPost)(struct entity_state_s* state, int e, edict_t* ent, edict
player_params[id].prevangles = player_params_history[host_id].hist[SV_UPDATE_MASK & (_host_client->netchan.outgoing_sequence)][id].angles;
player_params[id].prevframe = player_params_history[host_id].hist[SV_UPDATE_MASK & (_host_client->netchan.outgoing_sequence)][id].frame;
player_params[id].prevsequence = player_params_history[host_id].hist[SV_UPDATE_MASK & (_host_client->netchan.outgoing_sequence)][id].sequence;

if (player_params[id].sequence < 0)
player_params[id].sequence = 0;

// sequence has changed, hold the previous sequence info
if (player_params[id].sequence != player_params[id].prevsequence)
{
Expand Down

0 comments on commit 4f1c268

Please sign in to comment.