ValveSoftware / halflife

Half-Life 1 engine based games
Other
3.66k stars 616 forks source link

wrong code in StudioRenderer #1655

Open hzqst opened 8 years ago

hzqst commented 8 years ago

in StudioModelRenderer.h there is an issue at line 143 that don't cause any crash or error. it will crash when you (or any modders) are trying to access them

// Pointers to current body part and submodel
    mstudiobodyparts_t *m_pBodyPart;
    mstudiomodel_t  *m_pSubModel;

should be

// Pointers to current body part and submodel
    mstudiobodyparts_t **m_pBodyPart;
    mstudiomodel_t  **m_pSubModel;

Since in engine we have:

mstudiobodyparts_t  *pbodypart;
mstudiomodel_t      *psubmodel;
void studioapi_SetupModel( int bodypart, void **ppbodypart, void **ppsubmodel )
{
    R_StudioSetupModel( bodypart );

    *ppbodypart = &pbodypart;
    *ppsubmodel = &psubmodel;
}

after calling *ppbodypart = &pbodypart;

you have the a pointer to pbodypart in m_pBodyPart instead of the actual value of pbodypart, which means you get a pointer to the pointer to the actual mstudiobodyparts_t struct.

and you should get access to the mstudiobodyparts_t struct by using (*m_pBodyPart)->

the m_pSubModel has the same nature.

tschumann commented 8 years ago

You should add a pull request to fix this.

tschumann commented 8 years ago

@hzqst is the engine code you posted from Quake?

hzqst commented 8 years ago

@tschumann it's decompiled from Goldsrc engine (hw.dll