From a7f8584661de92996fe97ac60eec6c212c51a9b7 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Fri, 10 Apr 2020 08:30:22 +0300 Subject: [PATCH] Allow routines to have configurable error reporting that is individual from global setting. Potential fix for error handling that was being used in a way that had the opposite intended effect. --- module/Misc/Routine.cpp | 4 ++++ module/Misc/Routine.hpp | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/module/Misc/Routine.cpp b/module/Misc/Routine.cpp index 4d927da7..2ce450d3 100644 --- a/module/Misc/Routine.cpp +++ b/module/Misc/Routine.cpp @@ -18,6 +18,7 @@ Routine::Time Routine::s_Last = 0; Routine::Time Routine::s_Prev = 0; Routine::Interval Routine::s_Intervals[SQMOD_MAX_ROUTINES]; Routine::Instance Routine::s_Instances[SQMOD_MAX_ROUTINES]; +bool Routine::s_Silenced = false; // ------------------------------------------------------------------------------------------------ void Routine::Process() @@ -57,6 +58,7 @@ void Routine::Process() void Routine::Initialize() { std::memset(s_Intervals, 0, sizeof(s_Intervals)); + SetSilenced(!ErrorHandling::IsEnabled()); } // ------------------------------------------------------------------------------------------------ @@ -349,6 +351,8 @@ void Register_Routine(HSQUIRRELVM vm) .Func(_SC("GetArgument"), &Routine::GetArgument) .Func(_SC("DropEnv"), &Routine::DropEnv) .StaticFunc(_SC("UsedCount"), &Routine::GetUsed) + .StaticFunc(_SC("AreSilenced"), &Routine::GetSilenced) + .StaticFunc(_SC("SetSilenced"), &Routine::SetSilenced) ); // Global functions RootTable(vm).SquirrelFunc(_SC("SqRoutine"), &Routine::Create); diff --git a/module/Misc/Routine.hpp b/module/Misc/Routine.hpp index 1a84d808..165b3a82 100644 --- a/module/Misc/Routine.hpp +++ b/module/Misc/Routine.hpp @@ -54,7 +54,7 @@ private: , mIterations(0) , mInterval(0) , mSuspended(false) - , mQuiet(ErrorHandling::IsEnabled()) + , mQuiet(GetSilenced()) , mEndure(false) , mArgc(0) , mArgv() @@ -213,6 +213,7 @@ private: static Time s_Prev; // Previous time point. static Interval s_Intervals[SQMOD_MAX_ROUTINES]; // List of intervals to be processed. static Instance s_Instances[SQMOD_MAX_ROUTINES]; // List of routines to be executed. + static bool s_Silenced; // Error reporting independent from global setting. private: @@ -639,6 +640,22 @@ public: { GetValid().mEnv.Release(); } + + /* -------------------------------------------------------------------------------------------- + * See if error reporting is enabled for all newlly created routines. + */ + static bool GetSilenced() + { + return s_Silenced; + } + + /* -------------------------------------------------------------------------------------------- + * Set if error reporting should be enabled for all newlly created routines. + */ + static void SetSilenced(bool toggle) + { + s_Silenced = toggle; + } }; } // Namespace:: SqMod