From b7437591462734473bf0db38ff5975bf919e988c Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Tue, 22 Jan 2019 20:35:23 +0100 Subject: [PATCH] Lock Variables while adding to it to prevent threading issues --- Upsilon/Evaluator/EvaluationScope.cs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Upsilon/Evaluator/EvaluationScope.cs b/Upsilon/Evaluator/EvaluationScope.cs index 7cd6504..51b1b97 100644 --- a/Upsilon/Evaluator/EvaluationScope.cs +++ b/Upsilon/Evaluator/EvaluationScope.cs @@ -40,17 +40,20 @@ namespace Upsilon.Evaluator public void AssignToNearest(VariableSymbol symbol, ScriptType value) { - if (Variables.ContainsKey(symbol.Name)) + lock (Variables) { - Variables[symbol.Name] = value; - } - else if (ParentScope != null) - { - ParentScope.AssignToNearest(symbol, value); - } - else - { - Variables.Add(symbol.Name, value); + if (Variables.ContainsKey(symbol.Name)) + { + Variables[symbol.Name] = value; + } + else if (ParentScope != null) + { + ParentScope.AssignToNearest(symbol, value); + } + else + { + Variables.Add(symbol.Name, value); + } } }