Skip to content

Commit

Permalink
Fix improperly initialized thread static field.
Browse files Browse the repository at this point in the history
  • Loading branch information
homothetyhk committed Feb 20, 2022
1 parent 4dbfbed commit 5491313
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion RandomizerCore/Json/LMConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public override void WriteJson(JsonWriter writer, LogicManager value, JsonSerial

writer.WritePropertyName(nameof(value.VariableResolver));
serializer.Serialize(writer, value.VariableResolver, typeof(VariableResolver));
Log($"Serialized VR as {value.VariableResolver.GetType().Name}");

writer.WriteEndObject();
serializer.Converters.Remove(LogicDefConverter.Instance);
Expand Down
8 changes: 4 additions & 4 deletions RandomizerCore/Json/RandoContextConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace RandomizerCore.Json
{
public class RandoContextConverter : JsonConverter<RandoContext>
{
[ThreadStatic] public static bool canWrite = true;
public override bool CanWrite => canWrite;
[ThreadStatic] public static bool inUse;
public override bool CanWrite => !inUse;

public override RandoContext ReadJson(JsonReader reader, Type objectType, RandoContext existingValue, bool hasExistingValue, JsonSerializer serializer)
{
Expand Down Expand Up @@ -38,9 +38,9 @@ public override void WriteJson(JsonWriter writer, RandoContext value, JsonSerial
serializer.Converters.Add(tc);
serializer.Converters.Add(LogicDefConverter.Instance);

canWrite = false;
inUse = true;
serializer.Serialize(writer, value);
canWrite = true;
inUse = false;

serializer.Converters.Remove(LogicDefConverter.Instance);
serializer.Converters.Remove(tc);
Expand Down

0 comments on commit 5491313

Please sign in to comment.