mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-02-07 17:01:21 +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 ID_TIME_T FILE_NOT_FOUND_TIMESTAMP = 0xFFFFFFFF;
|
||||||
static const int MAX_PURE_PAKS = 128;
|
static const int MAX_PURE_PAKS = 128;
|
||||||
static const int MAX_OSPATH = FILENAME_MAX;
|
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;
|
*pic = NULL;
|
||||||
}
|
}
|
||||||
if ( timestamp ) {
|
if ( timestamp ) {
|
||||||
*timestamp = 0xFFFFFFFF;
|
*timestamp = FILE_NOT_FOUND_TIMESTAMP;
|
||||||
}
|
}
|
||||||
if ( width ) {
|
if ( width ) {
|
||||||
*width = 0;
|
*width = 0;
|
||||||
|
@ -978,7 +978,7 @@ void R_LoadImage( const char *cname, byte **pic, int *width, int *height, ID_TIM
|
||||||
|
|
||||||
if ( ext == "tga" ) {
|
if ( ext == "tga" ) {
|
||||||
LoadTGA( name.c_str(), pic, width, height, timestamp ); // try tga first
|
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.StripFileExtension();
|
||||||
name.DefaultFileExtension( ".jpg" );
|
name.DefaultFileExtension( ".jpg" );
|
||||||
LoadJPG( name.c_str(), pic, width, height, timestamp );
|
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" ) ) {
|
if ( !token.Icmp( "addnormals" ) ) {
|
||||||
byte *pic2;
|
byte *pic2 = NULL;
|
||||||
int width2, height2;
|
int width2, height2;
|
||||||
|
|
||||||
MatchAndAppendToken( src, "(" );
|
MatchAndAppendToken( src, "(" );
|
||||||
|
@ -454,7 +454,7 @@ static bool R_ParseImageProgram_r( idLexer &src, byte **pic, int *width, int *he
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !token.Icmp( "add" ) ) {
|
if ( !token.Icmp( "add" ) ) {
|
||||||
byte *pic2;
|
byte *pic2 = NULL;
|
||||||
int width2, height2;
|
int width2, height2;
|
||||||
|
|
||||||
MatchAndAppendToken( src, "(" );
|
MatchAndAppendToken( src, "(" );
|
||||||
|
@ -589,7 +589,7 @@ static bool R_ParseImageProgram_r( idLexer &src, byte **pic, int *width, int *he
|
||||||
// load it as an image
|
// load it as an image
|
||||||
R_LoadImage( token.c_str(), pic, width, height, ×tamp, true );
|
R_LoadImage( token.c_str(), pic, width, height, ×tamp, true );
|
||||||
|
|
||||||
if ( timestamp == -1 ) {
|
if ( timestamp == FILE_NOT_FOUND_TIMESTAMP ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue