From b0d022f5599fb202287861307b15fcec5e919345 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 27 Jan 2019 05:56:36 +0100 Subject: [PATCH] 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) --- neo/framework/FileSystem.h | 2 ++ neo/renderer/Image_files.cpp | 4 ++-- neo/renderer/Image_program.cpp | 6 +++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/neo/framework/FileSystem.h b/neo/framework/FileSystem.h index 529ed5bd..ad1a8de2 100644 --- a/neo/framework/FileSystem.h +++ b/neo/framework/FileSystem.h @@ -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; diff --git a/neo/renderer/Image_files.cpp b/neo/renderer/Image_files.cpp index 24436c80..6d62e4e7 100644 --- a/neo/renderer/Image_files.cpp +++ b/neo/renderer/Image_files.cpp @@ -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 ); diff --git a/neo/renderer/Image_program.cpp b/neo/renderer/Image_program.cpp index e7ec7eeb..1a02b872 100644 --- a/neo/renderer/Image_program.cpp +++ b/neo/renderer/Image_program.cpp @@ -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; }