Print script errors to the console at all times

This change prints script errors and their callstack to the console even when sq_showvmoutput < 2 (this avoids confusion when running a dedicated server and the server 'appears' to shutdown the game on its own. You could also check the script log files which are written to at all times, but having some indication is nice).
This commit is contained in:
Kawe Mazidjatari 2022-08-08 17:49:46 +02:00
parent fccff58d0b
commit 8fde529e2b
4 changed files with 26 additions and 4 deletions

View File

@ -11,6 +11,8 @@
bool g_bSQAuxError = false; bool g_bSQAuxError = false;
bool g_bSQAuxBadLogic = false; bool g_bSQAuxBadLogic = false;
HSQUIRRELVM g_pErrorVM = nullptr;
SQInteger sqstd_aux_printerror(HSQUIRRELVM v) SQInteger sqstd_aux_printerror(HSQUIRRELVM v)
{ {
g_bSQAuxError = true; g_bSQAuxError = true;
@ -21,6 +23,8 @@ SQInteger sqstd_aux_printerror(HSQUIRRELVM v)
SQInteger sqstd_aux_badlogic(HSQUIRRELVM v, __m128i* a2, __m128i* a3) SQInteger sqstd_aux_badlogic(HSQUIRRELVM v, __m128i* a2, __m128i* a3)
{ {
g_pErrorVM = v;
SQInteger results = v_sqstd_aux_badlogic(v, a2, a3); SQInteger results = v_sqstd_aux_badlogic(v, a2, a3);
return results; return results;
} }

View File

@ -1,6 +1,9 @@
#pragma once #pragma once
#include "sqtype.h"
extern bool g_bSQAuxError; extern bool g_bSQAuxError;
extern bool g_bSQAuxBadLogic; extern bool g_bSQAuxBadLogic;
extern HSQUIRRELVM g_pErrorVM;
inline CMemory p_sqstd_aux_printerror; inline CMemory p_sqstd_aux_printerror;
inline auto v_sqstd_aux_printerror = p_sqstd_aux_printerror.RCast<SQInteger(*)(HSQUIRRELVM v)>(); inline auto v_sqstd_aux_printerror = p_sqstd_aux_printerror.RCast<SQInteger(*)(HSQUIRRELVM v)>();

View File

@ -105,7 +105,8 @@ SQRESULT SQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...)
if (sq_showvmoutput->GetInt() > 0) { if (sq_showvmoutput->GetInt() > 0) {
sqlogger->debug(vmStr); sqlogger->debug(vmStr);
} }
if (sq_showvmoutput->GetInt() > 1) if (sq_showvmoutput->GetInt() > 1 ||
(g_bSQAuxError || g_bSQAuxBadLogic && v == g_pErrorVM))
{ {
bool bError = false; bool bError = false;
bool bColorOverride = false; bool bColorOverride = false;
@ -334,10 +335,15 @@ void SQVM_CompileError(HSQUIRRELVM v, const SQChar* pszError, const SQChar* pszF
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
void SQVM_LogicError(SQBool bPrompt) void SQVM_LogicError(SQBool bPrompt)
{ {
if (*g_flErrorTimeStamp > 0.0 && (bPrompt || Plat_FloatTime() > *g_flErrorTimeStamp + 0.0)) if ((*g_flErrorTimeStamp) > 0.0 && (bPrompt || Plat_FloatTime() > (*g_flErrorTimeStamp) + 0.0))
{ {
g_bSQAuxBadLogic = true; g_bSQAuxBadLogic = true;
} }
else
{
g_bSQAuxBadLogic = false;
g_pErrorVM = nullptr;
}
v_SQVM_LogicError(bPrompt); v_SQVM_LogicError(bPrompt);
} }

View File

@ -11,12 +11,21 @@ struct SQVM
{ {
return _vftable; return _vftable;
} }
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) && !defined (GAMEDLL_S2)
SQCONTEXT GetContext() const SQCONTEXT GetContext() const
{ {
#if !defined (GAMEDLL_S0) && !defined (GAMEDLL_S1) && !defined (GAMEDLL_S2)
return _contextidx; return _contextidx;
#else // This is the only way to obtain the context directly in anything <S3 without involving global script pointers.
if (strcmp(_sharedstate->_contextname, "SERVER") == 0)
return SQCONTEXT::SERVER;
if (strcmp(_sharedstate->_contextname, "CLIENT") == 0)
return SQCONTEXT::CLIENT;
if (strcmp(_sharedstate->_contextname, "UI") == 0)
return SQCONTEXT::UI;
return SQCONTEXT::NONE;
#endif // !GAMEDLL_S0 && !GAMEDLL_S1 && !GAMEDLL_S2
} }
#endif
SQVM* _vftable; SQVM* _vftable;
_BYTE gap000[16]; _BYTE gap000[16];