Restore unsafe execution context to its previous value

This commit is contained in:
alexey.lysiuk 2018-01-30 15:56:45 +02:00
parent f4191f27cf
commit c8b6e5719e

View file

@ -129,6 +129,23 @@ FButtonStatus Button_Mlook, Button_Klook, Button_Use, Button_AltAttack,
bool ParsingKeyConf, UnsafeExecutionContext; bool ParsingKeyConf, UnsafeExecutionContext;
class UnsafeExecutionScope
{
const bool wasEnabled;
public:
explicit UnsafeExecutionScope(const bool enable = true)
: wasEnabled(UnsafeExecutionContext)
{
UnsafeExecutionContext = enable;
}
~UnsafeExecutionScope()
{
UnsafeExecutionContext = wasEnabled;
}
};
// To add new actions, go to the console and type "key <action name>". // To add new actions, go to the console and type "key <action name>".
// This will give you the key value to use in the first column. Then // This will give you the key value to use in the first column. Then
// insert your new action into this list so that the keys remain sorted // insert your new action into this list so that the keys remain sorted
@ -226,10 +243,8 @@ void DWaitingCommand::Tick ()
{ {
if (--TicsLeft == 0) if (--TicsLeft == 0)
{ {
const bool wasUnsafe = UnsafeExecutionContext; UnsafeExecutionScope scope;
UnsafeExecutionContext = IsUnsafe;
AddCommandString (Command); AddCommandString (Command);
UnsafeExecutionContext = wasUnsafe;
Destroy (); Destroy ();
} }
} }
@ -677,9 +692,8 @@ DEFINE_ACTION_FUNCTION(DOptionMenuItemCommand, DoCommand)
if (CurrentMenu == nullptr) return 0; if (CurrentMenu == nullptr) return 0;
PARAM_PROLOGUE; PARAM_PROLOGUE;
PARAM_STRING(cmd); PARAM_STRING(cmd);
UnsafeExecutionContext = true; UnsafeExecutionScope scope;
C_DoCommand(cmd); C_DoCommand(cmd);
UnsafeExecutionContext = false;
return 0; return 0;
} }
@ -1508,9 +1522,8 @@ void FConsoleAlias::SafeDelete ()
void FUnsafeConsoleAlias::Run (FCommandLine &args, APlayerPawn *instigator, int key) void FUnsafeConsoleAlias::Run (FCommandLine &args, APlayerPawn *instigator, int key)
{ {
UnsafeExecutionContext = true; UnsafeExecutionScope scope;
FConsoleAlias::Run(args, instigator, key); FConsoleAlias::Run(args, instigator, key);
UnsafeExecutionContext = false;
} }
void FExecList::AddCommand(const char *cmd, const char *file) void FExecList::AddCommand(const char *cmd, const char *file)