engine: common: mod_studio: fix NULL mod->cache.data if model has split texture file but none was loaded

This commit is contained in:
Alibek Omarov 2024-06-12 23:37:30 +03:00
parent 240b6fb6f2
commit 2dbafbda02

View file

@ -866,6 +866,7 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
{ {
char poolname[MAX_VA_STRING]; char poolname[MAX_VA_STRING];
studiohdr_t *phdr; studiohdr_t *phdr;
qboolean textures_loaded = false;
Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name ); Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name );
@ -874,8 +875,10 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
mod->type = mod_studio; mod->type = mod_studio;
phdr = R_StudioLoadHeader( mod, buffer ); phdr = R_StudioLoadHeader( mod, buffer );
if( !phdr ) return; // bad model if( !phdr )
return; // bad model
#if !XASH_DEDICATED
if( !Host_IsDedicated( ) && phdr->numtextures == 0 ) if( !Host_IsDedicated( ) && phdr->numtextures == 0 )
{ {
studiohdr_t *thdr; studiohdr_t *thdr;
@ -889,10 +892,9 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
byte *in, *out; byte *in, *out;
size_t size1, size2; size_t size1, size2;
#if !XASH_DEDICATED
// TODO: Mod_StudioLoadTextures will crash if passed a merged studio model! // TODO: Mod_StudioLoadTextures will crash if passed a merged studio model!
ref.dllFuncs.Mod_StudioLoadTextures( mod, thdr ); ref.dllFuncs.Mod_StudioLoadTextures( mod, thdr );
#endif textures_loaded = true;
// give space for textures and skinrefs // give space for textures and skinrefs
size1 = thdr->numtextures * sizeof( mstudiotexture_t ); size1 = thdr->numtextures * sizeof( mstudiotexture_t );
@ -916,7 +918,9 @@ void Mod_LoadStudioModel( model_t *mod, const void *buffer, qboolean *loaded )
if( buffer2 ) if( buffer2 )
Mem_Free( buffer2 ); // release T.mdl Mem_Free( buffer2 ); // release T.mdl
} }
else #endif
if( !textures_loaded )
{ {
// NOTE: don't modify source buffer because it's used for CRC computing // NOTE: don't modify source buffer because it's used for CRC computing
mod->cache.data = Mem_Calloc( mod->mempool, phdr->length ); mod->cache.data = Mem_Calloc( mod->mempool, phdr->length );