Skip to content

Commit

Permalink
Merge pull request scp-fs2open#6277 from Goober5000/improve_model_tex…
Browse files Browse the repository at this point in the history
…ture_parsing

improve model texture parsing
  • Loading branch information
Goober5000 authored Jul 29, 2024
2 parents 693a4a3 + 1fae61b commit d057c0b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion code/model/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,7 @@ int model_create_instance(int objnum, int model_num);
void model_delete_instance(int model_instance_num);

// Goober5000
void model_load_texture(polymodel *pm, int i, char *file);
void model_load_texture(polymodel *pm, int i, const char *file);

SCP_set<int> model_get_textures_used(const polymodel* pm, int submodel);

Expand Down
10 changes: 8 additions & 2 deletions code/model/modelread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2662,8 +2662,14 @@ modelread_status read_model_file_no_subsys(polymodel * pm, const char* filename,
//mprintf(0," num textures = %d\n",n);
for (i=0; i<n; i++ )
{
char tmp_name[256];
char tmp_name[127];
cfread_string_len(tmp_name,127,fp);
constexpr int max_buffer_size = MAX_FILENAME_LEN - 8; // leave room for the longest suffix, "-reflect"
if (strlen(tmp_name) >= max_buffer_size)
{
Warning(LOCATION, "Model '%s', texture '%s' filename is too long! Truncating to %d characters.", pm->filename, tmp_name, max_buffer_size - 1);
tmp_name[max_buffer_size - 1] = '\0';
}
model_load_texture(pm, i, tmp_name);
//mprintf(0,"<%s>\n",name_buf);
}
Expand Down Expand Up @@ -3121,7 +3127,7 @@ modelread_status read_and_process_model_file(polymodel* pm, const char* filename


//Goober
void model_load_texture(polymodel *pm, int i, char *file)
void model_load_texture(polymodel *pm, int i, const char *file)
{
// NOTE: it doesn't help to use more than MAX_FILENAME_LEN here as bmpman will use that restriction
// we also have to make sure there is always a trailing NUL since overflow doesn't add it
Expand Down

0 comments on commit d057c0b

Please sign in to comment.