Skip to content

Commit 931c5f9

Browse files
committed
ensure PopulateEntries doesn't add entries more than once
1 parent dce2503 commit 931c5f9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

CSync/Lib/SyncedConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.Reflection;
44
using System.Runtime.Serialization;
5+
using System.Threading;
56
using CSync.Extensions;
67
using HarmonyLib;
78
using JetBrains.Annotations;
@@ -16,6 +17,7 @@ namespace CSync.Lib;
1617
public class SyncedConfig<T> : SyncedInstance<T>, ISyncedConfig where T : SyncedConfig<T>
1718
{
1819
public ISyncedEntryContainer EntryContainer { get; } = new SyncedEntryContainer();
20+
private int _entryContainerPopulated = 0;
1921

2022
public SyncedConfig(string guid)
2123
{
@@ -36,6 +38,7 @@ public SyncedConfig(string guid)
3638

3739
internal void PopulateEntryContainer()
3840
{
41+
if (Interlocked.Exchange(ref _entryContainerPopulated, 1) != 0) return;
3942
foreach (var fieldInfo in SyncedEntryFields.Value)
4043
{
4144
var entryBase = (SyncedEntryBase)fieldInfo.GetValue(this);

0 commit comments

Comments
 (0)