Allow more than 32 surfaces in skin files

Models don't have a surface limit; skins shouldn't either. Some player
models require more than 32 surfaces since vanilla Quake 3 did not
enforce the limit.

Skins are now limited to 256 surfaces because having no limit would
require parsing the skin file twice. The skin surfaces are dynamically
allocated so it doesn't increase memory usage when less surfaces
are used.
This commit is contained in:
Zack Middleton 2017-07-04 13:48:52 -05:00
parent 4dffc52c1d
commit 904bbc1a8f
10 changed files with 54 additions and 32 deletions

View file

@ -766,6 +766,12 @@ typedef struct {
//=================================================================================
// max surfaces per-skin
// This is an arbitry limit. Vanilla Q3 only supported 32 surfaces in skins but failed to
// enforce the maximum limit when reading skin files. It was possile to use more than 32
// surfaces which accessed out of bounds memory past end of skin->surfaces hunk block.
#define MAX_SKIN_SURFACES 256
// skins allow models to be retextured without modifying the model file
typedef struct {
char name[MAX_QPATH];
@ -775,7 +781,7 @@ typedef struct {
typedef struct skin_s {
char name[MAX_QPATH]; // game path, including extension
int numSurfaces;
skinSurface_t *surfaces[MD3_MAX_SURFACES];
skinSurface_t *surfaces; // dynamically allocated array of surfaces
} skin_t;