From ec4697fb1157e0161b2d61b0578e49faa044fbb7 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Tue, 17 May 2022 03:51:04 +0200 Subject: [PATCH] Improve some messages in game code - TestHugeTranslation() prints positions (and asserts only afterwards), from "Work around assertion in alphalabs4, fix #409" - idCompiler::CompileFile() prints proper filename from "Fix usage of invalid pointer in idCompiler::CompileFile()" --- d3xp/physics/Clip.cpp | 17 +++++++++-------- d3xp/script/Script_Compiler.cpp | 10 +++++++++- game/physics/Clip.cpp | 6 +++++- game/script/Script_Compiler.cpp | 10 +++++++++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/d3xp/physics/Clip.cpp b/d3xp/physics/Clip.cpp index c82ca84..f1fb123 100644 --- a/d3xp/physics/Clip.cpp +++ b/d3xp/physics/Clip.cpp @@ -965,14 +965,6 @@ idClip::TestHugeTranslation */ ID_INLINE bool TestHugeTranslation( trace_t &results, const idClipModel *mdl, const idVec3 &start, const idVec3 &end, const idMat3 &trmAxis ) { if ( mdl != NULL && ( end - start ).LengthSqr() > Square( CM_MAX_TRACE_DIST ) ) { -#ifndef CTF - // May be important: This occurs in CTF when a player connects and spawns - // in the PVS of a player that has a flag that is spawning the idMoveableItem - // "nuggets". The error seems benign and the assert was getting in the way - // of testing. - assert( 0 ); -#endif - results.fraction = 0.0f; results.endpos = start; results.endAxis = trmAxis; @@ -984,6 +976,15 @@ ID_INLINE bool TestHugeTranslation( trace_t &results, const idClipModel *mdl, co } else { gameLocal.Printf( "huge translation for clip model %d\n", mdl->GetId() ); } + gameLocal.Printf( " from (%.2f %.2f %.2f) to (%.2f %.2f %.2f)\n", start.x, start.y, start.z, end.x, end.y, end.z); + +#ifndef CTF + // May be important: This occurs in CTF when a player connects and spawns + // in the PVS of a player that has a flag that is spawning the idMoveableItem + // "nuggets". The error seems benign and the assert was getting in the way + // of testing. + assert( 0 ); +#endif return true; } return false; diff --git a/d3xp/script/Script_Compiler.cpp b/d3xp/script/Script_Compiler.cpp index 8e6e308..7f28d8e 100644 --- a/d3xp/script/Script_Compiler.cpp +++ b/d3xp/script/Script_Compiler.cpp @@ -28,6 +28,7 @@ If you have questions concerning this license or the applicable additional terms #include "sys/platform.h" #include "idlib/Timer.h" +#include "framework/FileSystem.h" #include "script/Script_Thread.h" #include "Game_local.h" @@ -2620,6 +2621,8 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon compile_time.Start(); + idStr origFileName = filename; // DG: filename pointer might become invalid when calling NextToken() below + scope = &def_namespace; basetype = NULL; callthread = false; @@ -2687,6 +2690,11 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon compile_time.Stop(); if ( !toConsole ) { - gameLocal.Printf( "Compiled '%s': %u ms\n", filename, compile_time.Milliseconds() ); + // DG: filename can be overwritten by NextToken() (via gameLocal.program.GetFilenum()), so + // use a copy, origFileName, that's still valid here. Furthermore, the path is nonsense, + // as idProgram::CompileText() called fileSystem->RelativePathToOSPath() on it + // which does not return the *actual* full path of that file but invents one, + // so revert that to the relative filename which at least isn't misleading + gameLocal.Printf( "Compiled '%s': %u ms\n", fileSystem->OSPathToRelativePath(origFileName), compile_time.Milliseconds() ); } } diff --git a/game/physics/Clip.cpp b/game/physics/Clip.cpp index c6c5c91..b2a237b 100644 --- a/game/physics/Clip.cpp +++ b/game/physics/Clip.cpp @@ -965,7 +965,7 @@ idClip::TestHugeTranslation */ ID_INLINE bool TestHugeTranslation( trace_t &results, const idClipModel *mdl, const idVec3 &start, const idVec3 &end, const idMat3 &trmAxis ) { if ( mdl != NULL && ( end - start ).LengthSqr() > Square( CM_MAX_TRACE_DIST ) ) { - assert( 0 ); + results.fraction = 0.0f; results.endpos = start; @@ -979,6 +979,10 @@ ID_INLINE bool TestHugeTranslation( trace_t &results, const idClipModel *mdl, co } else { gameLocal.Printf( "huge translation for clip model %d\n", mdl->GetId() ); } + + gameLocal.Printf( " from (%.2f %.2f %.2f) to (%.2f %.2f %.2f)\n", start.x, start.y, start.z, end.x, end.y, end.z); + + assert( 0 ); return true; } return false; diff --git a/game/script/Script_Compiler.cpp b/game/script/Script_Compiler.cpp index 196d463..5ee0c77 100644 --- a/game/script/Script_Compiler.cpp +++ b/game/script/Script_Compiler.cpp @@ -28,6 +28,7 @@ If you have questions concerning this license or the applicable additional terms #include "sys/platform.h" #include "idlib/Timer.h" +#include "framework/FileSystem.h" #include "script/Script_Thread.h" #include "Game_local.h" @@ -2620,6 +2621,8 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon compile_time.Start(); + idStr origFileName = filename; // DG: filename pointer might become invalid when calling NextToken() below + scope = &def_namespace; basetype = NULL; callthread = false; @@ -2687,6 +2690,11 @@ void idCompiler::CompileFile( const char *text, const char *filename, bool toCon compile_time.Stop(); if ( !toConsole ) { - gameLocal.Printf( "Compiled '%s': %u ms\n", filename, compile_time.Milliseconds() ); + // DG: filename can be overwritten by NextToken() (via gameLocal.program.GetFilenum()), so + // use a copy, origFileName, that's still valid here. Furthermore, the path is nonsense, + // as idProgram::CompileText() called fileSystem->RelativePathToOSPath() on it + // which does not return the *actual* full path of that file but invents one, + // so revert that to the relative filename which at least isn't misleading + gameLocal.Printf( "Compiled '%s': %u ms\n", fileSystem->OSPathToRelativePath(origFileName), compile_time.Milliseconds() ); } }