mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-01-31 13:40:38 +00:00
Fix crash when selecting nonexistant texture in D3Radiant
When selecting a texture in Inspectors -> Media -> Textures that doesn't really exist (.mtr defines it, but referenced image files are missing), the game/editor used to crash. The problem was that somehow people thought the best way to communicate that a file wasn't found was by setting the timestamp to 0xFFFFFFFF and then checking for that - sometimes (incorrectly) by comparing it to -1. That worked for 32bit ID_TIME_T (typedefed to time_t), but not with 64bit time_t, which now seems to be the default for Win32 in VS. So I replaced a few -1 and 0xFF... with FILE_NOT_FOUND_TIMESTAMP and now it works. FILE_NOT_FOUND_TIMESTAMP is still defined as 0xFFFFFFFF, maybe I should change that, unsure if that'd break anything though.. When changing it one should keep in mind that time_t might still be 32bit on some platforms (Linux x86?) so that should still work.. (-1 could work)
This commit is contained in:
parent
9a95a2a1cf
commit
b0d022f559
3 changed files with 7 additions and 5 deletions
|
@ -57,6 +57,8 @@ If you have questions concerning this license or the applicable additional terms
|
|||
===============================================================================
|
||||
*/
|
||||
|
||||
// FIXME: DG: this assumes 32bit time_t, but it's 64bit now, at least on some platforms incl. Win32 in modern VS
|
||||
// => change it (to -1?) or does that break anything?
|
||||
static const ID_TIME_T FILE_NOT_FOUND_TIMESTAMP = 0xFFFFFFFF;
|
||||
static const int MAX_PURE_PAKS = 128;
|
||||
static const int MAX_OSPATH = FILENAME_MAX;
|
||||
|
|
|
@ -957,7 +957,7 @@ void R_LoadImage( const char *cname, byte **pic, int *width, int *height, ID_TIM
|
|||
*pic = NULL;
|
||||
}
|
||||
if ( timestamp ) {
|
||||
*timestamp = 0xFFFFFFFF;
|
||||
*timestamp = FILE_NOT_FOUND_TIMESTAMP;
|
||||
}
|
||||
if ( width ) {
|
||||
*width = 0;
|
||||
|
@ -978,7 +978,7 @@ void R_LoadImage( const char *cname, byte **pic, int *width, int *height, ID_TIM
|
|||
|
||||
if ( ext == "tga" ) {
|
||||
LoadTGA( name.c_str(), pic, width, height, timestamp ); // try tga first
|
||||
if ( ( pic && *pic == 0 ) || ( timestamp && *timestamp == -1 ) ) {
|
||||
if ( ( pic && *pic == 0 ) || ( timestamp && *timestamp == FILE_NOT_FOUND_TIMESTAMP ) ) {
|
||||
name.StripFileExtension();
|
||||
name.DefaultFileExtension( ".jpg" );
|
||||
LoadJPG( name.c_str(), pic, width, height, timestamp );
|
||||
|
|
|
@ -403,7 +403,7 @@ static bool R_ParseImageProgram_r( idLexer &src, byte **pic, int *width, int *he
|
|||
}
|
||||
|
||||
if ( !token.Icmp( "addnormals" ) ) {
|
||||
byte *pic2;
|
||||
byte *pic2 = NULL;
|
||||
int width2, height2;
|
||||
|
||||
MatchAndAppendToken( src, "(" );
|
||||
|
@ -454,7 +454,7 @@ static bool R_ParseImageProgram_r( idLexer &src, byte **pic, int *width, int *he
|
|||
}
|
||||
|
||||
if ( !token.Icmp( "add" ) ) {
|
||||
byte *pic2;
|
||||
byte *pic2 = NULL;
|
||||
int width2, height2;
|
||||
|
||||
MatchAndAppendToken( src, "(" );
|
||||
|
@ -589,7 +589,7 @@ static bool R_ParseImageProgram_r( idLexer &src, byte **pic, int *width, int *he
|
|||
// load it as an image
|
||||
R_LoadImage( token.c_str(), pic, width, height, ×tamp, true );
|
||||
|
||||
if ( timestamp == -1 ) {
|
||||
if ( timestamp == FILE_NOT_FOUND_TIMESTAMP ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue