Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GameKit implementation of "AddUnique" does not match documented behavior #579

Closed
petergiuntoli opened this issue Dec 22, 2023 · 1 comment
Labels
Bug Something isn't working Resolved Pending Release

Comments

@petergiuntoli
Copy link
Contributor

I wasn't sure if this was brought in from somewhere else or is home grown but AddUnique is documented as returning true if adding an element but it actually returns true if the element already exists.

/// <summary>
/// Adds an entry to a list if it does not exist already.
/// </summary>
/// <returns>True if being added.</returns>
public static bool AddUnique<T>(this List<T> list, object value)
{
bool contains = list.Contains((T)value);
if (!contains)
list.Add((T)value);
return contains;
}

I notice that this is causing unintended behavior inside "CanvasTracker"

/// <summary>
/// Adds a canvas to OpenCanvases if not already added.
/// </summary>
/// <param name="addToBlocking">True to also add as an input blocking canvas.</param>
/// <returns>True if the canvas was added, false if already added.</returns>
public static bool AddOpenCanvas(object canvas, bool addToBlocking)
{
bool added = _openCanvases.AddUnique(canvas);
if (added && addToBlocking)
_inputBlockingCanvases.Add(canvas);
return added;
}

Additionally I think the function signature could make the "object" a type T instead of boxing internally but that's a separate issue.

public static bool AddUnique<T>(this List<T> list, T value)

I ended up noticing this because my game has it's own implementation of AddUnique but vscode chooses to autocomplete the "gamekit" version first which has the opposite return value behavior.

petergiuntoli added a commit to PlayOneMoreGame/FishNet that referenced this issue Dec 23, 2023
Change to take in a T instead of potentially boxing to an object and back.
Change return value to match documented behavior of returning true if
value is added

FirstGearGames#579
@FirstGearGames FirstGearGames added Bug Something isn't working Resolved Pending Release labels Dec 28, 2023
@FirstGearGames
Copy link
Owner

You are right on both. Fixed and improved in v3.11.14 and 4.0.7.

FirstGearGames pushed a commit that referenced this issue Jan 12, 2024
- Added TransportManager.Get/SetMTUReserve(int) to allow reserving bytes in buffers, such as use with IntermediateLayer to insert encryption data. Reserving bytes does not consume more bandwidth if bytes are not filled.
- Improved TransportManager.GetMTU methods to consider reserve.
- Improved exposed TimeManager.PingInterval.
- Fixed Fish-Networking menu item order.
- Improved created replicates which arrive after the run tick are now run in replays instead of twice.
- Changed ReplicateState.UserCreated renamed to CurrentCreated for clarity.
- Changed ReplicateState.Predicted renamed to CurrentPredicted for clarity.
- Changed ReplicateState.ReplayedPredicted/UserCreated renamed to Replayed.
- Added ReplicateState.Future to indicate future prediction of objects.
- Changed SceneLoad/UnloadData PreferredScene is now a structure.
- Added SceneLoad/UnloadData PreferredScene can now specify different scenes for client and server.
- Fixed Prediction v2 reconcile desyncs for NonAuthoritative.
- Fixed Prediction v2 reconcile desyncs for Authoritative.
- Improved RigidbodyPauser to be simplified and more flexible for edge-case setups.
- Fixed Prediction v2 garbage allocation from physics.
- Fixed Prediction v2 excessive replays of remote objects when local client was not moving.
- Removed NetworkManager.StaticLogXYZ methods.
- Added NetworkManagerExtensions.Log/Warnig/Error.
- Added Log/Warning/Error extensions for NetworkManager references; null references may be used.
- Improved NetworkManager logging methods now use Unity debug when NetworkManager does not exist in any scene.
- Improved ServerManager.ShareIds made public.
- Improved BufferLast always uses reliable channel for new observers now.
- Fixed a SyncType not being set dirty by server within OnStartServer due to no observers count, resulting in predicted spawners not getting the new value update.
- Added Prediction v2 teleport option for graphical object.
- Improved List.AddUnique now returns if added, as well value no longer boxes. (#579)(#580)
- Fixed preferred scene not being applied to global scenes for late joiners (#585)
- Fixed inversed transform offsets in GetTransformOffsets and SetTransformOffsets. (#578)
- Fixed DistanceCondition causing flickering due to incorrect hide distance calculation. (#576)
FirstGearGames pushed a commit that referenced this issue Jan 14, 2024
- Fixed preferred scene not being applied to global scenes for late joiners (#585)
- Fixed TicksToTime(PreciseTick pt) returning incorrect values.
- Improved exposed TimeManager.PingInterval.
- Improved accuracy printout for ColliderRollback demo.
- Improved PreciseTick legibility and potentially accuracy slightly.
- Improved List.AddUnique now returns if added, as well value no longer boxes. (#579)
- Fixed inversed transform offsets in GetTransformOffsets and SetTransformOffsets. (#578)
- Fixed PredictedBullet, predicted spawning example, within Rigidbody Prediction v1 demo.
- Improved notes and explanations on predicted spawning example.
- Fixed a SyncType not being set dirty by server within OnStartServer due to no observers count, resulting in predicted spawners not getting the new value update.
- Removed all prediction v2 logic and demos. Only v4 and up will support prediction v2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Resolved Pending Release
Projects
None yet
Development

No branches or pull requests

2 participants