Skip to content

Commit 8ec10c5

Browse files
author
FirstGearGames
committed
4.6.17R
- Fixed ObjectCache collections not being initialized due to multi-threading support for Unity 6+.
1 parent cd61ea3 commit 8ec10c5

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

Assets/FishNet/Runtime/Managing/NetworkManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ internal void SetBroadcastName<T>(ushort key) where T : struct, IBroadcast
232232
/// <summary>
233233
/// Version of this release.
234234
/// </summary>
235-
public const string FISHNET_VERSION = "4.6.16";
235+
public const string FISHNET_VERSION = "4.6.17";
236236
/// <summary>
237237
/// Maximum framerate allowed.
238238
/// </summary>

Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/ObjectCaching.cs

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using GameKit.Dependencies.Utilities.Types;
34
using System.Collections.Generic;
45
using System.Runtime.CompilerServices;
@@ -155,18 +156,12 @@ public static void Store(Dictionary<T1, T2> value)
155156
/// <summary>
156157
/// Cache for ResettableRingBuffer.
157158
/// </summary>
158-
[ThreadStatic]
159-
private static readonly Stack<ResettableRingBuffer<T>> _resettableRingBufferCache;
159+
private static readonly ConcurrentStack<ResettableRingBuffer<T>> _resettableRingBufferCache = new();
160160
/// <summary>
161161
/// Maximum number of entries allowed for the cache.
162162
/// </summary>
163163
private const int MAXIMUM_CACHE_COUNT = 50;
164-
165-
static ResettableCollectionCaches()
166-
{
167-
_resettableRingBufferCache = new();
168-
}
169-
164+
170165
/// <summary>
171166
/// Retrieves a collection.
172167
/// </summary>
@@ -465,18 +460,12 @@ public static class CollectionCaches<T1, T2>
465460
/// <summary>
466461
/// Cache for dictionaries.
467462
/// </summary>
468-
[ThreadStatic]
469-
private static readonly Stack<Dictionary<T1, T2>> _dictionaryCache;
463+
private static readonly ConcurrentStack<Dictionary<T1, T2>> _dictionaryCache = new();
470464
/// <summary>
471465
/// Maximum number of entries allowed for the cache.
472466
/// </summary>
473467
private const int MAXIMUM_CACHE_COUNT = 50;
474468

475-
static CollectionCaches()
476-
{
477-
_dictionaryCache = new();
478-
}
479-
480469
/// <summary>
481470
/// Retrieves a collection.
482471
/// </summary>
@@ -525,33 +514,27 @@ public static class CollectionCaches<T>
525514
/// <summary>
526515
/// Cache for arrays.
527516
/// </summary>
528-
[ThreadStatic]
529-
private static readonly Stack<T[]> _arrayCache;
517+
private static readonly ConcurrentStack<T[]> _arrayCache = new();
530518
/// <summary>
531519
/// Cache for lists.
532520
/// </summary>
533-
[ThreadStatic]
534-
private static readonly Stack<List<T>> _listCache;
521+
private static readonly ConcurrentStack<List<T>> _listCache = new();
535522
/// <summary>
536523
/// Cache for sortedset.
537524
/// </summary>
538-
[ThreadStatic]
539-
private static readonly Stack<SortedSet<T>> _sortedSetCache;
525+
private static readonly ConcurrentStack<SortedSet<T>> _sortedSetCache = new();
540526
/// <summary>
541527
/// Cache for queues.
542528
/// </summary>
543-
[ThreadStatic]
544-
private static readonly Stack<Queue<T>> _queueCache;
529+
private static readonly ConcurrentStack<Queue<T>> _queueCache = new();
545530
/// <summary>
546531
/// Cache for queues.
547532
/// </summary>
548-
[ThreadStatic]
549-
private static readonly Stack<BasicQueue<T>> _basicQueueCache;
533+
private static readonly ConcurrentStack<BasicQueue<T>> _basicQueueCache = new();
550534
/// <summary>
551535
/// Cache for hashset.
552536
/// </summary>
553-
[ThreadStatic]
554-
private static readonly Stack<HashSet<T>> _hashSetCache;
537+
private static readonly ConcurrentStack<HashSet<T>> _hashSetCache = new();
555538
/// <summary>
556539
/// Maximum number of entries allowed for the cache.
557540
/// </summary>
@@ -861,18 +844,12 @@ public static void Store(HashSet<T> value)
861844
/// <summary>
862845
/// Stack to use.
863846
/// </summary>
864-
[ThreadStatic]
865-
private static readonly Stack<T> _stack;
847+
private static readonly ConcurrentStack<T> _stack = new();
866848
/// <summary>
867849
/// Maximum number of entries allowed for the cache.
868850
/// </summary>
869851
private const int MAXIMUM_CACHE_COUNT = 50;
870852

871-
static ObjectCaches()
872-
{
873-
_stack = new();
874-
}
875-
876853
/// <summary>
877854
/// Returns a value from the stack or creates an instance when the stack is empty.
878855
/// </summary>

0 commit comments

Comments
 (0)